我想为精灵添加一个延迟,所以当我进入一个新场景它不会立即播放时,任何建议都会非常感谢
如果有帮助的话,那就是精灵的代码
//SPRITES BIRD ONE -------------------------
//------------------------------------------
CCSpriteFrameCache *cache=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache addSpriteFramesWithFile:@"house-ipad.plist"];
// frame array
NSMutableArray *framesArray=[NSMutableArray array];
for (int i=1; i<24; i++) {
NSString *frameName=[NSString stringWithFormat:@"house-ipad%d.png", i];
id frameObject=[cache spriteFrameByName:frameName];
[framesArray addObject:frameObject];
}
// animation object
id animObject=[CCAnimation animationWithFrames:framesArray delay:0.035];
// animation action;
id animAction=[CCAnimate actionWithAnimation:animObject restoreOriginalFrame:NO];
//id animAction=[CCAnimate actionWithDuration:4 animation:animObject restoreOriginalFrame:NO];
//animAction=[CCRepeatForever actionWithAction:animAction];
// sprite (width,height)
CCSprite *bird=[CCSprite spriteWithSpriteFrameName:@"house-ipad1.png"];
bird.position=ccp(550,470);
// batchNode
CCSpriteBatchNode *batchNode=[CCSpriteBatchNode batchNodeWithFile:@"house-ipad.png"];
[self addChild:batchNode];
[batchNode addChild:bird];
[bird runAction:animAction];
//-----------------------------------------
答案 0 :(得分:1)
创建一个添加新精灵的新方法,并在延迟后调用它:
[self performSelector:@selector(afterDelay:) withObject:animAction afterDelay:0.5];
-(void)afterDelay:(id)animAction
{
// sprite (width,height)
CCSprite *bird=[CCSprite spriteWithSpriteFrameName:@"house-ipad1.png"];
bird.position=ccp(550,470);
// batchNode
CCSpriteBatchNode *batchNode=[CCSpriteBatchNode batchNodeWithFile:@"house-ipad.png"];
[self addChild:batchNode];
[batchNode addChild:bird];
[bird runAction:animAction];
}