多个精灵动作

发布于 2024-10-29 00:42:13 字数 1383 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有伤那来痛 2024-11-05 00:42:13

要从其他方法启动操作,您必须保留该操作
例如:[动作保留];然后不要忘记释放它

-(void)create{
    for( int q=1;q<12;q++){
        [playerWalkAnim addFrameWithFilename: [NSString stringWithFormat:@"walkforward_%.2d.png", q]];
    }
    playerAction = [CCAnimate actionWithAnimation:playerWalkAnim];
    playerAction.duration = 2;

    [playerAction retain];
}

-(void)launch{
    [player1 runAction:playerAction];
}

To launch an action from another method, you have to retain the action
Eg: [action retain]; and then do not forget to release it

-(void)create{
    for( int q=1;q<12;q++){
        [playerWalkAnim addFrameWithFilename: [NSString stringWithFormat:@"walkforward_%.2d.png", q]];
    }
    playerAction = [CCAnimate actionWithAnimation:playerWalkAnim];
    playerAction.duration = 2;

    [playerAction retain];
}

-(void)launch{
    [player1 runAction:playerAction];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文