1

以下のようなスプライトのアクションを実行したい:

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***
}

関数呼び出しで値を送信するにはどうすればよいですか。助けてください

4

1 に答える 1

0

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 を使用することですが、タグ付きのオプションの方が簡単だと思います:)

于 2014-08-23T06:49:14.877 に答える