OGeek|极客世界-中国程序员成长平台

标题: ios - Spritebuilder 如何以编程方式更改 CCNode 的动画(CCB 文件)? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 04:22
标题: ios - Spritebuilder 如何以编程方式更改 CCNode 的动画(CCB 文件)?

我正在尝试制作一个 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'



Best Answer-推荐答案


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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4