Cocos2d 等待问题

问题描述: 如果我想让一个 sprite 显示3秒钟然后消失,应该怎么做?

解决:使用 CCDelayTime 和 CCCallFunc

CCSprite *sprite = [CCSprite spriteWithFile:@"blabla.png"];
[layer addChild:sprite];
CCDelayTime* waitAction = [CCDelayTime actionWithDuration:3]; //等待3秒
CCCallFunc* vanishAction = [CCCallFunc actionWithTarget:self selector:@selector(removeSprite:)]; //调用removeSprite:方法
CCSequence* sequence = [CCSequence actions:waitAction, vanishAction, nil];
[sprite runAction:sequence];

// 在 removeSprite: 里
[sprite removeFromParentAndCleanup:YES];
posted @ 2011-06-12 17:21  木乃猫  阅读(952)  评论(0编辑  收藏  举报