多个精灵动作
我正在使用 Cocos2d 引擎,但遇到了一个奇怪的问题。
我有一个精灵。另外,我有两个该精灵的动画。我想在应用程序加载时播放一个动画,然后在调用 ccTouchevent 后播放第二个动画。
walkAnim = [CCAnimation animation];
dropAnim = [CCAnimation animation];
for( int q=1;q<12;q++){
[walkAnim addFrameWithFilename: [NSString stringWithFormat:@"walkforward_%.2d.png", q]];
[dropAnim addFrameWithFilename: [NSString stringWithFormat:@"drop_%.2d.png", q]];
}
action = [CCAnimate actionWithAnimation:walkAnim];
action.duration = 2;
id act = [CCRepeatForever actionWithAction:action];
[sprite runAction:act];
所以,在这里我们看到一个动画精灵。
[sprite stopAllActions]; //and here my torture begins
我尝试了很多创建动作的方法:
我尝试添加另一个 AnimateAction,尝试替换当前动画,但一切都会导致崩溃。
[action setAnimation:dropAnim];
并且
CCAnimate* animat = [[CCAnimate alloc]initWithDuration:30 animation:dropAnim restoreOriginalFrame:YES];
谢谢
id action = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:dropAnim]];
[player1 runAction:action];
崩溃发生在 [CCAnimate actionWithAnimation:]
+(id) actionWithAnimation: (CCAnimation*)anim
{
return [[[self alloc] initWithAnimation:anim restoreOriginalFrame:YES] autorelease];
}
!
要从另一种方法启动操作,您必须保留该操作
例如:[操作保留];
I am using Cocos2d engine and I've faced a strange problem.
I have a sprite. Also, I have 2 animations for that sprite. And I want to play one animation when app loads and second, after ccTouchevent is called.
walkAnim = [CCAnimation animation];
dropAnim = [CCAnimation animation];
for( int q=1;q<12;q++){
[walkAnim addFrameWithFilename: [NSString stringWithFormat:@"walkforward_%.2d.png", q]];
[dropAnim addFrameWithFilename: [NSString stringWithFormat:@"drop_%.2d.png", q]];
}
action = [CCAnimate actionWithAnimation:walkAnim];
action.duration = 2;
id act = [CCRepeatForever actionWithAction:action];
[sprite runAction:act];
So, here we see an animating sprite.
[sprite stopAllActions]; //and here my torture begins
I have tried many ways of creating an action:
I've tried to add another AnimateAction, tried to replace the current animation, but everything results in a crash.
[action setAnimation:dropAnim];
and
CCAnimate* animat = [[CCAnimate alloc]initWithDuration:30 animation:dropAnim restoreOriginalFrame:YES];
and
id action = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:dropAnim]];
[player1 runAction:action];
The crash is in [CCAnimate actionWithAnimation:]
+(id) actionWithAnimation: (CCAnimation*)anim
{
return [[[self alloc] initWithAnimation:anim restoreOriginalFrame:YES] autorelease];
}
Thanks!
To launch an action from another method, you have to retain the action
Eg: [action retain];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从其他方法启动操作,您必须保留该操作
例如:[动作保留];然后不要忘记释放它
To launch an action from another method, you have to retain the action
Eg: [action retain]; and then do not forget to release it