【问题标题】:Cocos2d-x: add parameter in callfuncN_selectorCocos2d-x:在callfuncN_selector中添加参数
【发布时间】:2014-08-22 15:10:14
【问题描述】:

我想为如下精灵运行动作:

CCRotateTo* actionTo = CCRotateTo::create(0.2, 0.0f, -90.0f);

CCRotateTo* actionToBack = CCRotateTo::create(0.2, 0.0f, -180.0f);

CCFiniteTimeAction* actionChangeTexture = CCCallFuncN::create(this,
    callfuncN_selector(Paddle::spriteChangeTextture));**//*i want to send value here***

runAction(CCSequence::create(actionTo,actionChangeTexture,actionToBack, NULL));


void Paddle::spriteChangeTextture(CCNode* sender) {
  ***//i want to using parameter here, it's integer value***
}

如何在函数调用中发送值。 请帮忙

【问题讨论】:

    标签: c++ cocos2d-x ccsprite cocos2d-x-2.x ccaction


    【解决方案1】:

    您可以在 CCNode 中使用标签。在您的节点 setTag 中使用您的值。当您的操作被调用时,您可以简单地从发件人的标签中获取您的价值。

    CCRotateTo* actionTo = CCRotateTo::create(0.2, 0.0f, -90.0f);
    
    CCRotateTo* actionToBack = CCRotateTo::create(0.2, 0.0f, -180.0f);
    
    CCFiniteTimeAction* actionChangeTexture = CCCallFuncN::create(this,
        callfuncN_selector(Paddle::spriteChangeTextture));
    int value;
    setTag(value); // <-------- 
    runAction(CCSequence::create(actionTo,actionChangeTexture,actionToBack, NULL));
    
    
    void Paddle::spriteChangeTextture(CCNode* sender) {
    
    int value = sender->getTag; // <------------
    }
    

    当您可以将节点和数据作为参数传递时,另一个选项是使用 CCCallFuncND,但我认为带有标签的选项更简单:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      相关资源
      最近更新 更多