问题描述: 如果我想让一个 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];

相关文章:

  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2023-03-28
  • 2021-05-13
猜你喜欢
  • 2021-12-01
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案