【问题标题】:Spritebuilder how can I change the animation ( CCB file ) of a CCNode programmatically?Spritebuilder 如何以编程方式更改 CCNode 的动画(CCB 文件)?
【发布时间】:2014-12-29 08:13:01
【问题描述】:

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

【问题讨论】:

  • 那是因为 animar 是一个 CCNode(或子类)实例,而不是 CCSpriteFrame

标签: ios animation cocos2d-iphone spritebuilder


【解决方案1】:

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"];

【讨论】:

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