我创建了一个CCAnimation,如下所示。我尝试将延迟降低到低于.05f,现在动画无法完成!它只有8帧。我不知道我做错了什么。起初我以为这是一个内存泄漏,我正在失去动作,所以我将它分配给一个强大的属性来测试它,并且仍然做到了。我不确定延迟会如何导致我的动画无法完成。我在模拟器中以每秒60帧的速度运行。
使用Kobold 2.0.4
有人可以帮忙吗?
else if([model currentState] == PROCESSING_FIRST_ACTION)
{
CCDirector* director = [CCDirector sharedDirector]; // process model
//Get the top left corner of the screen
int screen_height = director.screenSizeAsPoint.y;
int screen_width = director.screenSizeAsPoint.x;
id attacker = [model attacker];
id attackChoice = [attacker getRegisteredAttack];
CCAction* attack = [model.resourceManager animation: @"simple-attack-frame"];
CCSprite * attackSprite = [model.resourceManager sprite: @"simple-attack-frame-01"];
attackSprite.position = ccp(screen_width - rxa(80), screen_height - rya(80));
attackSprite.tag = 5;
self.action = attack;
CCNode * check = [self getChildByTag:5];
if(check == nil)
{
[self addChild: attackSprite];
[attackSprite runAction:attack];
}
}
resource manager:
-(id)animation: (NSString*)_resource
{
NSMutableArray *frames = [NSMutableArray array];
for(int i = 1; i <= 8; ++i)
{
[frames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@-0%d", _resource, i]]];
}
CCAnimation *animation = [CCAnimation animationWithSpriteFrames: frames delay:1/60];
CCAction * action = [CCAnimate actionWithAnimation: animation];
return action;
}
答案 0 :(得分:1)
在你的行
CCAnimation *animation = [CCAnimation animationWithSpriteFrames: frames delay:1/60];
你将延迟设置为1/60,但由于1和60都是整数,1/60是0.尝试使用1.0f / 60.0f,你将获得浮点除法。
答案 1 :(得分:0)
在网上挖掘后,我找到了解决方案。我不是提交此解决方案的人,但我可以证明它解决了我的问题:
https://github.com/cocos2d/cocos2d-iphone/commit/60f9cc98783b9a6a5635db4f468f83e0511c74c8