Cocos2D-x游戏开发之八:事件连续执行:CCMoveBy CCCallFunc CCSequence
2014-03-21 22:20
399 查看
接下来让我们继续基础知识的最后一节,将各种事件按照先后顺序连接起来是一件非常重要的事情,这一节我们做一个简单的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);
}
我先执行移动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 游戏开发之巧用CCDelayTIme实现多个action有序执行,使用CCCallFunc添加action回调
- Cocos2D-x游戏开发之七:CCMoveBy CCJumpBy CCRotateBy CCAction CCRepeatForever
- 【Cocos2d-x 游戏开发】 2 --- Button、CCMoveBy
- Cocos2D-x游戏开发之六:CCMoveTo CCMoveBy and CCscaleTo CCBlink
- cocos2d中CCCallFunc、CCCallFuncN和CCCallFuncND的区别
- Cocos2d-x编程中CCRemoveSelf与CCCallFunc系列函数不能一起使用
- quick-cocos2d-x游戏开发【10】——触摸捕获事件 cc.NODE_TOUCH_CAPTURE_EVENT
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- (转)【iOS-cocos2d-X 游戏开发之十】自定义CCSprite/Layer/CCNode及静态类模版&自定义类细节说明&Cocos2dx触屏事件讲解
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- Cocos2D-x游戏开发之二十三:CCNotificationCenter观察者模式(2)-不同层之间事件的发送和接受
- cocos2d中CCCallFunc、CCCallFuncN和CCCallFuncND的区别
- cocos2d中CCCallFunc、CCCallFuncN和CCCallFuncND的区别
- Quick-Cocos2d-x游戏开发触摸捕获事件 cc.NODE_TOUCH_CAPTURE_EVENT
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例
- Cocos2d-x游戏开发——CCSequence&CCSpawn
- cocos2d-x中CCCallFunc CCCallFuncN CCCallFuncND的区别和使用示例