ios - Spritebuilder 如何以编程方式更改 CCNode 的动画(CCB 文件)?

标签 ios animation cocos2d-iphone spritebuilder

我正在尝试制作一个 Spritebuilder iPhone 游戏,我的主要角色 _player 是一个 CCNode,它的子节点是一个 CCBFile,它包含角色的空闲动画。

我想将此 _player 的 CCBFile 更改为另一个名为 ForwardDash.ccbi 的 CCBFile,其中包含玩家触摸屏幕时的“攻击”动画。

这就是我正在尝试的:

 //_player is a CCNode, its first child is the CCBFile with the idle animation.
 //animar is a pointer to the CCBFile with the ForwardDash animation

 CCSprite *wat = _player.children[0];
           CCNode *animar = [CCBReader load:@"ForwardDash"];
           [wat setSpriteFrame: (CCSpriteFrame*)animar];

它失败并给我错误:'Thread 1: signal SIGABRT'

最佳答案

setSpriteFrame 不是您正在寻找的方法。如果您想保留当前的 ​​CCB 设置,您应该能够通过执行以下操作来完成您想要的:

CCSprite *wat = _player.children[0];
[wat removeFromParent];
CCNode *animar = [CCBReader load:@"ForwardDash"];
[_player addChild:animar];

虽然这可行,但我建议您尝试利用 SpriteBuilder 中的不同动画时间轴。您可以将新时间线添加到 CCB 文件,然后以编程方式更改动画,而无需删除和添加新节点。您可以阅读更多关于使用时间线的信息 here .设置完成后,您将能够开始一个新的动画:

CCSprite *wat = _player.children[0];
CCAnimationManager* animationManager = wat.animationManager;
[animationManager runAnimationsForSequenceNamed:@"ForwardDash"];

关于ios - Spritebuilder 如何以编程方式更改 CCNode 的动画(CCB 文件)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27685498/

相关文章:

ios - XMPPFramework - 消息未发送

android - android 中的 clearAnimation() 和 stop() 有什么区别?

jquery - 制作动画时,如何仅在所有元素完成时才触发回调?

iphone - cocos2d中如何设置动画的帧

ios - 为什么当 ActiveReferenceCount > 0 时对象被取消初始化

ios - 苹果推送通知的可靠性

iphone - 是否有如何在 iOS 上使用 UIPopoverController 的示例?

python - 一个步骤的 Matplotlib 动画

iOS 游戏引擎选择

ios - Cocos2d,CCMenuSprite,缩放和定位问题