首页 > 其他 > 详细

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

时间:2014-03-22 00:02:17      阅读:306      评论:0      收藏:0      [点我收藏+]

接下来让我们继续基础知识的最后一节,将各种事件按照先后顺序连接起来是一件非常重要的事情,这一节我们做一个简单的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);
}bubuko.com,布布扣

Cocos2D-x游戏开发之事件连续执行:CCMoveBy CCCallFunc CCSequence,布布扣,bubuko.com

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

原文:http://blog.csdn.net/vanquishedzxl/article/details/21746941

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!