gpt4 book ai didi

c++ - cocos2dx。如何在动画序列之后设置回调(传递参数)

转载 作者:搜寻专家 更新时间:2023-10-31 01:46:56 32 4
gpt4 key购买 nike

我试图在一系列动画之后设置一个 Action ,基本上我需要使用一个对象(我想作为参数传递)作为一个方法。

我发现的唯一方法是使用 CCCallFunc,它(据我所知)不应该有参数。

是否存在一种 cocos2d/objective-c 的“callBlock”?这是一个很棒的工具,我想知道是否有类似cocos2d-x的东西

代码如下:

CCCallFuncND *callBack = CCCallFuncND::create(this, callfuncND_selector(MyObject::method), data);

因为我试图在一个只有静态函数的类(未初始化)中完成它,所以我不能使用“this”所以我试图将它设置为 NULL 但在这种情况下我得到了一个错误...

最佳答案

我必须做同样的事情,在运行一系列 Action 之后:我想从 bacthNode 中删除 Sprite ,这样我的动画帧就不会在动画结束时出现在屏幕上,所以我必须将批处理节点传递给功能,这就是我实现它的方式:-

CCSequence *seq=CCSequence::createWithTwoActions(
CCAnimate::create(animation),
CCCallFuncO::create(
animation,
callfuncO_selector(GameLayer::animationReshuffleFinished),
(CCObject*)animBatchNode)
);

您需要的函数是 CCCallFuncO 而不是 ND,这里 O 代表 Object。

CCCallFuncO::create(
animation,
callfuncO_selector(GameLayer::animationReshuffleFinished),
(CCObject*)animBatchNode)

animation 是我的 CCAnimate 对象animationReshuffleFinished 是我的类 GameLayer 的回调函数,我想在动画结束时调用它。并且 (CCObject*)animBatchNode) 是函数 animationReshuffleFinished 的参数

这里是函数的定义

 void GameLayer::animationReshuffleFinished(CCObject *sender){
CCSpriteBatchNode *animBatchNode = (CCSpriteBatchNode*) sender;
animBatchNode->cocos2d::CCNode::removeAllChildrenWithCleanup(true);
}

请让我知道这是否符合您的目的。

关于c++ - cocos2dx。如何在动画序列之后设置回调(传递参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19990389/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com