码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d 动作回调函数

时间:2014-09-02 00:05:53      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   数据   div   cti   

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    CCSize winSize = CCDirector::sharedDirector()->getWinSize(); 

    auto *png1=CCSprite::create("1.png");
    png1->setPosition(ccp(0,120));
    addChild(png1);


 
    CCFiniteTimeAction *action = CCSequence::create( 
        CCMoveBy::create(2.0f, CCPointMake(winSize.width / 2, 0)), 
        CCCallFunc::create(this, callfunc_selector(HelloWorld::actionCallback)), NULL); 
 
    CCFiniteTimeAction *actionN = CCSequence::create( 
        CCMoveBy::create(2.0f, CCPointMake(winSize.width / 2, 0)), 
        CCCallFuncN::create(this, callfuncN_selector(HelloWorld::actionCallbackN)), NULL); 
 
    CCFiniteTimeAction *actionND = CCSequence::create( 
        CCMoveBy::create(2.0f, CCPointMake(winSize.width / 2, 0)), 
        CCCallFuncND::create(this, callfuncND_selector(HelloWorld::actionCallbackND), (void *) "Callback Data"), NULL); 
 
    
    png1->runAction(action); 
    //png1->runAction(actionN); 
    //png1->runAction(actionND); 

    return true;
}

void HelloWorld::actionCallback()
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCLabelTTF *label = CCLabelTTF::create("Action Callback!", "Marker Felt", 32);
    label->setPosition(ccp(winSize.width / 2, winSize.height / 2));
    this->addChild(label);
}

void HelloWorld::actionCallbackN(CCNode *pSender) 
{ 
    CCSprite *sprite = (CCSprite *) pSender; 
 
    // 回调变红色  
    sprite->setColor(ccRED); 
} 

void HelloWorld::actionCallbackND(CCNode *pSender, void *data) 
{ 
    CCSize winSize = CCDirector::sharedDirector()->getWinSize(); 
    CCSprite *sprite = (CCSprite *) pSender; 
 
    // 回调变蓝色  
    sprite->setColor(ccBLUE); 
     
    // 接收回调数据  
    CCLabelTTF *label = CCLabelTTF::create((char *) data, "Marker Felt", 32); 
    label->setPosition(ccp(winSize.width / 2, winSize.height / 2)); 
    this->addChild(label); 
 
    CCLog((char *) data); 
} 

 

cocos2d 动作回调函数

标签:style   blog   color   os   io   ar   数据   div   cti   

原文地址:http://www.cnblogs.com/yufenghou/p/3950399.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!