cocos2d-x——CCCallFunc家族例子

boolHelloWorld::init()

{

    //

    // 1. super init first

   if ( !CCLayer::init() )

    {

        returnfalse;

    }

    

   CCSprite *sp = CCSprite::create("Icon.png");

    sp->setPosition(ccp(100,100));

   this->addChild(sp,01);

    

   CCLabelTTF *ttf = CCLabelTTF::create("函数回调动作","宋体",24);

    CCMenuItemLabel *label =CCMenuItemLabel::create(ttf,this,menu_selector(HelloWorld::menuCallback));

    label->setPosition(ccp(0,80));

   CCMenu *menu = CCMenu::create(label,NULL);

   this->addChild(menu);


    returntrue;

}


voidHelloWorld::menuCallback(CCObject* pSender)

{

   CCSprite* sp = (CCSprite*)this->getChildByTag(1);

   CCActionInterval* move = CCMoveTo::create(1,ccp(300,sp->getPositionY()));

//    //1

    CCCallFunc * funCall =CCCallFunc::create(this,callfunc_selector(HelloWorld::callbackC));

    

    

    

   //2

    //CCCallFuncN * funCall =CCCallFuncN::create(this, callfuncN_selector(HelloWorld::callbackN));

    

    

   //3

//    float *data = (float*)malloc(sizeof(float));

//    *data = 200;

//    CCCallFuncND * funCall =CCCallFuncND::create(this, callfuncND_selector(HelloWorld::callbackND), (void*)data);

    

    

    

//    //4

//    CCSprite *sp1 = CCSprite::create("Icon-72.png");

//    CCCallFuncO * funCall =CCCallFuncO::create(this, callfuncO_selector(HelloWorld::callbackO), (CCObject*)sp1);

//

    

    

    

    

    

    

    

   CCFiniteTimeAction *seq =CCSequence::create(move,funCall,NULL);

    sp->runAction(seq);

    ((CCMenuItemLabel *)pSender)->setEnabled(false);

}


voidHelloWorld::callbackC()

{

   CCSprite* sp = (CCSprite*)this->getChildByTag(1);

   this->removeChild(sp);

   CCLabelTTF *ttf = CCLabelTTF::create("移动动作执行完毕","仿宋",24);

    ttf->setPosition(ccp(300,150));

   this->addChild(ttf);

}


voidHelloWorld::callbackN(CCNode* sender)

{

   this->removeChild(sender);

   CCLabelTTF *ttf = CCLabelTTF::create("N移动动作执行完毕","仿宋",24);

    ttf->setPosition(ccp(300,150));

   this->addChild(ttf);

}


voidHelloWorld::callbackND(CCNode* sender,void* data)

{

   this->removeChild(sender);

   float y = *(float*)data;

   char str[100];

    sprintf(str,"ND移动动作执行完毕传过来的数据是:%f", y);

   CCLabelTTF *ttf = CCLabelTTF::create(str, "仿宋",24);

    ttf->setPosition(ccp(300, y));

   free(data);

   this->addChild(ttf);

}


voidHelloWorld::callbackO(CCObject* sender)

{

   CCLabelTTF *ttf = CCLabelTTF::create("O移动动作执行完毕","仿宋",24);

    ttf->setPosition(ccp(300,150));

   this->addChild(ttf);

   CCSprite *sp = (CCSprite*)sender;

    sp->setPosition(ccp(300,100));

   this->addChild(sp, -1);

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值