首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cocos2d动画不断崩溃

cocos2d动画不断崩溃
EN

Stack Overflow用户
提问于 2012-03-09 19:44:28
回答 1查看 228关注 0票数 1

我对cocos2d和o.c编程真的很陌生,我一直在尝试弄清楚精灵动画是如何工作的。由于最新的更新,我得到了很多不再工作的旧代码。

我有以下内容(一个有3个精灵的spriteheet,我想让它动起来)

不知何故,它一直在崩溃

这在我的init方法中

代码语言:javascript
复制
[[CCSpriteFrameCache sharedSpriteFrameCache ] addSpriteFramesWithFile:@"eno_glasses.plist" ];
        CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"eno_glasses.png"];
        [self addChild:spriteSheet];

        _body = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"eno_glasses02.png"]];        
        [spriteSheet addChild:_body];
        _body.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);



        NSMutableArray *animFrames = [NSMutableArray array];
        for(int i = 1; i < 3; i++) {
            CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"eno_glasses0%d.png",i]];
            [animFrames addObject:frame];
        }
        CCAnimation *animation = [CCAnimation animationWithFrames:animFrames delay:0.03f];
        CCAnimate* anime = [CCAnimate actionWithAnimation:animation];
        [self runAction:anime];  

我知道可以找到图像,因为这是可行的(我可以从plist 01,0,2,03中获取图像)

我是不是在什么地方忘了一个零?

代码语言:javascript
复制
 [[CCSpriteFrameCache sharedSpriteFrameCache ] addSpriteFramesWithFile:@"eno_glasses.plist" ];
        CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"eno_glasses.png"];
        [self addChild:spriteSheet];

        _body = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"eno_glasses02.png"]];        
        [spriteSheet addChild:_body];
        _body.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-09 21:36:45

使用:

代码语言:javascript
复制
[_body runAction:anime];

至于重复(假设一次)

代码语言:javascript
复制
id anime1=[CCAnimate actionWithAnimation:animation];
id delay=[CCDelayTime actionWithDuration:2.0f];
id anime2=[CCAnimate actionWithAnimation:animation];
id twice = [CCSequence actions:anime1,delay,anime2,nil];
[_body runAction:twice];

此外,您可能希望选择"eno_glasses01.png“作为您的开始帧。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9633512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档