Beispiel #1
0
bool GameOverLayer::init()
{
    if (!Layer::init())
    {
        return false;
    }
    initWithColor(Color4B(112, 128, 144, 150), 800, 450);
    auto bg = Sprite::createWithSpriteFrameName("lose_bg.png");
    addChild(bg);
    bg->setPosition(getContentSize()/2);
    auto restart = Sprite::createWithSpriteFrameName("menu_restart_normal_CN.png");
    addChild(restart);
    restart->setPosition(getContentSize().width / 2, getContentSize().height / 2 - 50);
    auto et = EventListenerTouchOneByOne::create();
    et->onTouchBegan = [restart](Touch* t, Event* e)->bool
    {
        if (restart->getBoundingBox().containsPoint(t->getLocation()))
        {

            Director::getInstance()->getRunningScene()->removeAllChildrenWithCleanup(true);

            auto scene = MainScene::createScene();
            Director::getInstance()->runWithScene(scene);
            Director::getInstance()->resume();
        }
        return true;
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(et, this);
    return true;
}
Beispiel #2
0
void OverLayer::initWithColorMenu(const Color4B color, Menu* menu)
{
    //init
    initWithColor(color);
    //add the menu
    addChild(menu);
}
Beispiel #3
0
bool PlayRunLayer::init(const cocos2d::Color4B &color){

    bool result =  initWithColor(color);
    
    //==============设置内容页大小==============
    //画面大小
    Size visibleSize = Director::getInstance()->getVisibleSize();
    //设置大小
    this->setContentSize(Size(visibleSize.width, gameConfig->contentHeight));
    //设置锚点
    this->setAnchorPoint(CCPoint::ZERO);
    float sideHeight = (visibleSize.height-gameConfig->contentHeight)/2;
    //设置位置
    this->setPosition(Point(0,sideHeight));
    
    scheduleUpdate();
    
    __NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(PlayRunLayer::auditionResume), POPT_AUDITION_RESUME , NULL);
    __NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(PlayRunLayer::auditionPause), POPT_AUDITION_PAUSE , NULL);
    
    //初始化伴奏信息
    accPlaying = false;
    
    accFileName= "music/stage/"+POPTStringUtils::intToString(poptGlobal->gni->getGameLevelInfo()->getLevel())+"/"+poptGlobal->gni->getMusic()+".mp3";
    CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic(accFileName.c_str());
    
    currentSection=-1;
    leftBlueToothSection = -1;
    rightBlueToothSection = -1;
    return result;
}
Beispiel #4
0
Scene* GameOverScene::createScene(cocos2d::CCDictionary *dic)
{
	auto scene = Scene::create();
	auto layer = GameOverScene::create();
    layer->initWithColor(Color4B::WHITE);
	layer->initDict(dic);
	scene->addChild(layer);
	return scene;
}
ParticleDemo::ParticleDemo(void)
{
	initWithColor( ccc4(127,127,127,255) );

	m_emitter = NULL;

	setIsTouchEnabled( true );
	
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 28);
	addChild(label, 100, 1000);
	label->setPosition( CCPointMake(s.width/2, s.height-50) );
	
	CCLabelTTF *tapScreen = CCLabelTTF::labelWithString("(Tap the Screen)", "Arial", 20);
	tapScreen->setPosition( CCPointMake(s.width/2, s.height-80) );
	addChild(tapScreen, 100);
	
	CCMenuItemImage* item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(ParticleDemo::backCallback) );
	CCMenuItemImage* item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(ParticleDemo::restartCallback) );
	CCMenuItemImage* item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2,  this, menu_selector(ParticleDemo::nextCallback) );
	
	CCMenuItemToggle* item4 = CCMenuItemToggle::itemWithTarget(	this, 
																menu_selector(ParticleDemo::toggleCallback), 
																CCMenuItemFont::itemFromString( "Free Movement" ),
                                                                CCMenuItemFont::itemFromString( "Relative Movement" ),
																CCMenuItemFont::itemFromString( "Grouped Movement" ),
																NULL );
	
	CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, item4, NULL);
		
	menu->setPosition( CCPointZero );
	item1->setPosition( CCPointMake( s.width/2 - 100,30) );
	item2->setPosition( CCPointMake( s.width/2, 30) );
	item3->setPosition( CCPointMake( s.width/2 + 100,30) );
	item4->setPosition( CCPointMake( 0, 100) );
	item4->setAnchorPoint( CCPointMake(0,0) );

	addChild( menu, 100 );	
	
    CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0000", "fonts/fps_images.png", 16, 24, '.');
    addChild(labelAtlas, 100, kTagLabelAtlas);
	labelAtlas->setPosition( CCPointMake(s.width-66,50) );
	
	// moving background
	m_background = CCSprite::spriteWithFile(s_back3);
	addChild(m_background, 5);
	m_background->setPosition( CCPointMake(s.width/2, s.height-180) );

	CCActionInterval* move = CCMoveBy::actionWithDuration(4, CCPointMake(300,0) );
	CCActionInterval* move_back = move->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions( move, move_back, NULL);
	m_background->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq) );
	
	
	schedule( schedule_selector(ParticleDemo::step) );
}
Beispiel #6
0
TextLayer::TextLayer(void)
{
	initWithColor( ccc4(32,32,32,255) );
		
	float x,y;
	
	CGSize size = CCDirector::sharedDirector()->getWinSize();
	x = size.width;
	y = size.height;
	
	CCNode* node = CCNode::node();
	CCActionInterval* effect = getAction();
	node->runAction(effect)
		;
	addChild(node, 0, kTagBackground);
	
	CCSprite *bg = CCSprite::spriteWithFile(s_back3);
	node->addChild(bg, 0);
	bg->setAnchorPoint( CGPointZero );

	CCSprite* grossini = CCSprite::spriteWithFile(s_pPathSister2);
	node->addChild(grossini, 1);
	grossini->setPosition( CGPointMake(x/3,y/2) );
	CCActionInterval* sc = CCScaleBy::actionWithDuration(2, 5);
	CCActionInterval* sc_back = sc->reverse();
	grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(sc, sc_back, NULL)) ) );

	CCSprite* tamara = CCSprite::spriteWithFile(s_pPathSister1);
	node->addChild(tamara, 1);
	tamara->setPosition( CGPointMake(2*x/3,y/2) );
	CCActionInterval* sc2 = CCScaleBy::actionWithDuration(2, 5);
	CCActionInterval* sc2_back = sc2->reverse();
	tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(sc2, sc2_back, NULL))) );
	
	CCLabelTTF* label = CCLabelTTF::labelWithString((effectsList[actionIdx]).c_str(), "Marker Felt", 32);
	
	label->setPosition( CGPointMake(x/2,y-80) );
	addChild(label);
	label->setTag( kTagLabel );

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TextLayer::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TextLayer::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TextLayer::nextCallback) );

	CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

	menu->setPosition( CGPointZero );
	item1->setPosition( CGPointMake( size.width/2 - 100,30) );
	item2->setPosition( CGPointMake( size.width/2, 30) );
	item3->setPosition( CGPointMake( size.width/2 + 100,30) );
	
	addChild(menu, 1);	

	schedule( schedule_selector(TextLayer::checkAnim) );
}
ColorButton* ColorButton::createWithColor(const Color4B& start,const Color4B& end){
	auto colorButton = new (std::nothrow) ColorButton();
	if (colorButton && colorButton->initWithColor(start, end)){
		colorButton->autorelease();
		return colorButton;
	}

	CC_SAFE_DELETE(colorButton);

	return nullptr;
}
Beispiel #8
0
bool PauseLayer::init()
{
	if (!LayerColor::init())
		return false;

	initWithColor(Color4B(162, 162, 162, 128));

	addUI();
	addTouch();
	return true;
}
Beispiel #9
0
/**
 * LayerRadialGradient
 */
LayerRadialGradient* LayerRadialGradient::create(const Color4B& startColor, const Color4B& endColor, float radius, const Vec2& center, float expand)
{
    auto layerGradient = new LayerRadialGradient();
    if (layerGradient && layerGradient->initWithColor(startColor, endColor, radius, center, expand))
    {
        layerGradient->autorelease();
        return layerGradient;
    }
    
    delete layerGradient;
    return nullptr;
}
Beispiel #10
0
LayerRadialGradient* LayerRadialGradient::create()
{
    auto layerGradient = new LayerRadialGradient();
    if (layerGradient && layerGradient->initWithColor(Color4B::BLACK, Color4B::BLACK, 0, Vec2(0,0), 0))
    {
        layerGradient->autorelease();
        return layerGradient;
    }
    
    delete layerGradient;
    return nullptr;
}
Beispiel #11
0
Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();
    layer->initWithColor(Color4B::WHITE);
    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}
Beispiel #12
0
TextLayer::TextLayer(void)
{
    initWithColor( ccc4(32,128,32,255) );
    
    CCNode* node = CCNode::create();
    CCActionInterval* effect = getAction();
    node->runAction(effect);
    addChild(node, 0, kTagBackground);
    
    CCSprite *bg = CCSprite::create(s_back3);
    node->addChild(bg, 0);
//  bg->setAnchorPoint( CCPointZero );
    bg->setPosition(VisibleRect::center());

    CCSprite* grossini = CCSprite::create(s_pPathSister2);
    node->addChild(grossini, 1);
    grossini->setPosition( ccp(VisibleRect::left().x+VisibleRect::getVisibleRect().size.width/3,VisibleRect::center().y) );
    CCActionInterval* sc = CCScaleBy::create(2, 5);
    CCActionInterval* sc_back = sc->reverse();
    grossini->runAction( CCRepeatForever::create(CCSequence::create(sc, sc_back, NULL) ) );

    CCSprite* tamara = CCSprite::create(s_pPathSister1);
    node->addChild(tamara, 1);
    tamara->setPosition( ccp(VisibleRect::left().x+2*VisibleRect::getVisibleRect().size.width/3,VisibleRect::center().y) );
    CCActionInterval* sc2 = CCScaleBy::create(2, 5);
    CCActionInterval* sc2_back = sc2->reverse();
    tamara->runAction( CCRepeatForever::create(CCSequence::create(sc2, sc2_back, NULL)) );
    
    CCLabelTTF* label = CCLabelTTF::create((effectsList[actionIdx]).c_str(), "Marker Felt", 32);
    
    label->setPosition( ccp(VisibleRect::center().x,VisibleRect::top().y-80) );
    addChild(label);
    label->setTag( kTagLabel );

    CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TextLayer::backCallback) );
    CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(TextLayer::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TextLayer::nextCallback) );

    CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);

    menu->setPosition(CCPointZero);
    item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
    item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
    item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
    
    addChild(menu, 1);    

    schedule( schedule_selector(TextLayer::checkAnim) );
}
Beispiel #13
0
DialogLayer * DialogLayer::create(const Color4B & color)
{

	auto layer = new DialogLayer();
	
	auto ss = Director::getInstance()->getWinSize();

	if (layer->initWithColor(color, ss.width, ss.height)) {
		layer->initListeners();
		layer->autorelease();
		
		return layer;
	}
	else {
		CC_SAFE_DELETE(layer);
		return nullptr;
	}
}
Beispiel #14
0
Scene* BattleScene::scene(const std::string& level)
{
    Scene *scene = Scene::createWithPhysics();
    Size size=Director::getInstance()->getVisibleSize();
    
    //通过ECS创建场景
    auto layer=new BattleScene();
    if( layer && layer->initWithColor(Color4B(255*0.91,255*0.91,255*0.91,255),size.width,size.height))
    {
        layer->autorelease();
        
        scene->getPhysicsWorld()->setGravity(Vect(0,0));

        GX::Entity* welcome=GX::GameSystem::getInstance()->getECS()->createEntity("Battle.json");
        layer->addChild(welcome->getNode());
        scene->addChild(layer);
    }
    
    return scene;
}
bool RobotLooseLayer::init()
{
    CCSize mapSize = GameParams::getInstanse()->mapSize();
    
    if ( !initWithColor(ccc4(145,145,145,255 * 0.45f)) )
    {
        return false;
    }
    
    CCLabelTTF *label = CCLabelTTF::create(CCLocalizedString("RobotBroken", "NotLocalized"), "Marker Felt", 42);
    
    label->setAnchorPoint( CCPointZero );
    label->setPosition( CCPointZero );
    
    addChild(label, 20);
    
    setContentSize(CCSizeMake(label->getContentSize().width, label->getContentSize().height));
    setPosition(ccp(mapSize.width / 2 - getContentSize().width / 2, -getContentSize().height));
    
    return true;
}
Beispiel #16
0
bool CCLayerGradient::init()
{
	return initWithColor(ccc4(0, 0, 0, 255), ccc4(0, 0, 0, 255));
}
Beispiel #17
0
bool LayerGradient::initWithColor(const Color4B& start, const Color4B& end)
{
    return initWithColor(start, end, Vec2(0, -1));
}
Beispiel #18
0
bool LayerGradient::init()
{
    return initWithColor(Color4B(0, 0, 0, 255), Color4B(0, 0, 0, 255));
}
Beispiel #19
0
bool LayerColor::initWithColor(const Color4B& color)
{
    Size s = Director::getInstance()->getWinSize();
    return initWithColor(color, s.width, s.height);
}
Beispiel #20
0
bool LayerColor::init()
{
    Size s = Director::getInstance()->getWinSize();
    return initWithColor(Color4B(0,0,0,0), s.width, s.height);
}
Beispiel #21
0
bool CCLayerGradient::initWithColor(const ccColor4B& start, const ccColor4B& end)
{
    return initWithColor(start, end, ccp(0, -1));
}
//-------------------------------------------------------------------------
bool FKCW_UIWidget_GradientView::init()
{
	return initWithColor(ccc4(0, 0, 0, 255), ccc4(0, 0, 0, 255));
}
Beispiel #23
0
bool CCLayerColor::init()
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    return initWithColor(ccc4(0,0,0,0), s.width, s.height);
}
Beispiel #24
0
bool CColorView::init()
{
	return initWithColor(Color4B(0, 0, 0, 0));
}
Beispiel #25
0
bool LayerWin::init()
{
    bool bRet = false;

    do
    {

        int curTitle = Global::shareGlobal()->curTitle;

        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
        CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();


        CC_BREAK_IF(!initWithColor(ccc4(250, 248, 239,255)));

        CCLabelTTF* label = CCLabelTTF::create(curTitle == 11 ? "YOU WIN!" : "GREAT!","Arial Bold",32,
            CCSize(visibleSize.width,visibleSize.height*0.7),kCCTextAlignmentCenter);

        CC_BREAK_IF(!label);

        label->setColor(ccc3(119,110,101));
        label->setPosition(ccp(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2));

        this->addChild(label);

        float rectX = visibleSize.width*0.75;
        float rectY = rectX*0.45;
        ColorRect* pRect = ColorRect::create(ccc4(236, 196, 0, 255),rectX,rectY);

        pRect->setPosition(origin.x + (visibleSize.width-rectX)/2,origin.y+(visibleSize.height)/2);

        this->addChild(pRect);


        CCString *ssv = CCString::createWithFormat("%d",1 << curTitle);
        CCLabelTTF* scoreValue = CCLabelTTF::create(ssv->getCString(),"Arial Bold",32,CCSize(rectX,rectY),
            kCCTextAlignmentCenter);

        this->addChild(scoreValue);
        scoreValue->setPosition(ccp(pRect->getPositionX()+rectX*0.5,pRect->getPositionY()+rectY*0.3));

        CCString *sst = CCString::createWithFormat("SCORE:%d",Global::shareGlobal()->curScore);
        CCLabelTTF* score = CCLabelTTF::create(sst->getCString(),"Arial Bold",8,CCSize(rectX,rectY*0.5),
            kCCTextAlignmentCenter);
        this->addChild(score);
        score->setPosition(ccp(pRect->getPositionX()+rectX*0.5,pRect->getPositionY()));

        
        float menuX = rectX*0.45;
        float menuY = menuX*0.3;


        TitleRect *titleBack = TitleRect::create(ccc4(187, 173, 160, 255),menuX,menuY,"Back");
        CCMenuItemLabel *MenuBack = CCMenuItemLabel::create(titleBack,this,menu_selector(LayerWin::menuBack));

        TitleRect *titleAgain = TitleRect::create(ccc4(187, 173, 160, 255),menuX,menuY,"Try again");
        CCMenuItemLabel *MenuAgain = CCMenuItemLabel::create(titleAgain,this,menu_selector(LayerWin::menuAgain));

        CCMenu *menu = CCMenu::create(MenuBack,MenuAgain,NULL);

        menu->alignItemsHorizontallyWithPadding(rectX*0.1);

        menu->setPositionY(origin.y+visibleSize.height*0.2);

        this->addChild(menu);


        bRet = true;
    }while(0);

    return bRet;
}
Beispiel #26
0
bool CGradientView::init()
{
	return initWithColor(ccc4(0, 0, 0, 255), ccc4(0, 0, 0, 255));
}
 static mc_Scene *create(void) {
     auto scene = new mc_Scene();
     scene->initWithColor(cocos2d::Color4B::BLACK);
     return scene;
 }
Beispiel #28
0
bool CGradientView::initWithColor(const ccColor4B& tStart, const ccColor4B& tEnd)
{
	return initWithColor(tStart, tEnd, CCPoint(0, -1));
}
Beispiel #29
0
bool GameWorld::init()
{
    wSize = Director::getInstance()->getVisibleSize();
    initWithColor(Color4B(240,240,240,240));
    auto spBack = Sprite::create("mainBack.png");
    spBack->setPosition(wSize.width/2, wSize.height/2);
    addChild(spBack);
    setOneStep();
    //pause button
    auto pauseSp = Sprite::create("plane.png", Rect(175, 148, 22, 23));
    auto btnPause = MenuItemSprite::create(pauseSp,
                                           pauseSp,
                                           CC_CALLBACK_1(GameWorld::onClick, this));
    btnPause->setTag(TAG_PAUSE);
    auto sizePause = btnPause->getContentSize();
    btnPause->setPosition(Point(sizePause.width, wSize.height - sizePause.height));
    //close button
    auto btnClose = MenuItemImage::create("CloseNormal.png",
                                          "CloseSelected.png",
                                          CC_CALLBACK_1(GameWorld::onClick, this));
    btnClose->setTag(TAG_CLOSE);
    
    auto abelttf=LabelTTF::create("Resume Game","Thonburi", 48);
    auto color = Color3B(126, 126, 126);
    abelttf->setColor(color);
    itemResume = MenuItemLabel::create(abelttf, CC_CALLBACK_1(GameWorld::onResume, this));
    itemResume->setPosition(wSize.width/2, wSize.height/2);
    itemResume->setVisible(false);
    auto menuResume = Menu::create(itemResume, NULL);
    addChild(menuResume);
    menuResume->setPosition(Point::ZERO);
    
    menu = Menu::create(btnPause, btnClose, NULL);
    menu->setPosition(Point::ZERO);
    addChild(menu);
    
    //score label
    scoreLabel = LabelBMFont::create("0", "konqa32.fnt");
    addChild(scoreLabel);
    scoreLabel->setPosition(btnPause->getPosition().x + btnPause->getContentSize().width + scoreLabel->getContentSize().width/2, btnPause->getPosition().y);
    _myPlane = Sprite::create("plane.png", Rect(2, 168, 62, 75));
    _myPlane->setPosition(Point(wSize.width/2, _myPlane->getContentSize().height/2));
    addChild(_myPlane);
    
    //
    CCLOG("schedule logic.");
    this->schedule(schedule_selector(GameWorld::gamelogic), 0.4);
    this->schedule(schedule_selector(GameWorld::addBullet),0.2);
    this->schedule(schedule_selector(GameWorld::addPackage),rand()%10+10);
    this->schedule(schedule_selector(GameWorld::updateSpeedRate), 5);
    this->schedule(schedule_selector(GameWorld::updategame));
    //
    //_targets = Array::create();
    //_bullets = new Array;
    this->speedRate = 1.0;
    doubleBulletFlag = false;
    onClickFlag = false;
    score = 0;
    
    //srand((unsigned)time(NULL));
    
    //add touch event.
    listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(GameWorld::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(GameWorld::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(GameWorld::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    return true;
}