精灵的时间延迟,cocos2d
我想为精灵添加延迟,这样当我进入一个新场景时,它不会立即播放,任何建议都会非常感谢,
这里是精灵的代码(如果有帮助的话)
//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];
//-----------------------------------------
i want to add a delay to a sprite so when i enter a new scene it doesnt play straight away, any advice would be greatful thanks
heres the code of the sprite if it helps
//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];
//-----------------------------------------
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个用于添加新精灵的新方法并在延迟后调用它:
create a new method for adding new sprite and call this after delay: