Cocos2D-x游戏开发之八:事件连续执行:CCMoveBy CCCallFunc CCSequence

接下来让我们继续基础知识的最后一节,将各种事件按照先后顺序连接起来是一件非常重要的事情,这一节我们做一个简单的Demo。

我先执行移动Action然后在移动完成之后再告诉你们我已经到家了。。

任然比较简单,代码如下:

bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        CC_BREAK_IF(! CCLayer::init());
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
            "CloseNormal.png",
            "CloseSelected.png",
            this,
            menu_selector(HelloWorld::menuCloseCallback));
        CC_BREAK_IF(! pCloseItem);
        pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));
        CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);


        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);
        // 3. Add add a splash screen, show the cocos2d splash image.
        CCSprite* pSprite = CCSprite::create("sprite.png");
        CC_BREAK_IF(! pSprite);
CCSize  size = CCDirector::sharedDirector()->getWinSize();
        pSprite->setPosition(ccp(0, size.height/2));
        this->addChild(pSprite, 0);
CCMoveBy *move= CCMoveBy::create(4.0f,ccp(size.width-50,size.height/4));
CCCallFunc *cal = CCCallFunc::create(this,callfunc_selector(HelloWorld::callfunc));


CCSequence *seo = CCSequence::create(move,cal,NULL);
pSprite->runAction(seo);
        bRet = true;
    } while (0);


    return bRet;
}


void HelloWorld::menuCloseCallback(CCObject* pSender)
{
    // "close" menu item clicked
    CCDirector::sharedDirector()->end();
}


void HelloWorld::callfunc()
{
CCLabelTTF *label  = CCLabelTTF::create("I am Home","Arial",35);
CCSize size = CCDirector::sharedDirector()->getWinSize();
label->setPosition(ccp(size.width-200,size.height/2));
this->addChild(label);
CCBlink *blink = CCBlink::create(6.0f,50);
label->runAction(blink);
}Cocos2D-x游戏开发之八:事件连续执行:CCMoveBy CCCallFunc CCSequence_第1张图片

你可能感兴趣的:(Cocos2D-x游戏开发之八:事件连续执行:CCMoveBy CCCallFunc CCSequence)