CCSprite在首次创建时冻结

时间:2014-09-19 10:26:56

标签: cocos2d-iphone ccsprite

在我的游戏应用程序中,当我第一次创建CCSprite并在屏幕上移动它时,我看到所有对象都冻结了...... 这是我创建动画精灵的代码

CCSprite *cassa = [CCSprite spriteWithImageNamed:@"cassa00.png"];

int minX = cassa.contentSize.width / 2;
int maxX = self.contentSize.width - cassa.contentSize.width / 2;
int rangeX = maxX - minX;
int randomX = (arc4random() % rangeX) + minX;

cassa.position = CGPointMake(randomX, self.contentSize.height + cassa.contentSize.height);
[self addChild:cassa z:70];
[cassaArray addObject:cassa];

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"cassa.plist"];
NSMutableArray *runningFrame = [NSMutableArray array];
for(int i = 0; i < 3; ++i) 
{
    [runningFrame addObject:
    [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
    [NSString stringWithFormat:@"cassa0%d.png", i]]];
}

CCAnimation *runningAnimation = [CCAnimation animationWithSpriteFrames:runningFrame delay:0.15f];
CCAction *turnAction = [CCActionRepeatForever actionWithAction:[CCActionAnimate actionWithAnimation:runningAnimation]];
    [cassa runAction:turnAction];

CCAction *actionMove = [CCActionMoveTo actionWithDuration:duration position:CGPointMake(randomX, -cassa.contentSize.height)];
CCAction *actionRemove = [CCActionRemove action];
[cassa runAction:[CCActionSequence actionWithArray:@[actionMove, actionRemove]]];

0 个答案:

没有答案