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];

你可能感兴趣的:(cocos2d)