在cocos2d中启动和停止粒子系统



我想问一下如何在iOS/cocos2d中启动粒子系统,让它运行一定的时间,比如10秒,然后停止。

一个小的代码片段或例子,将作为一个指南,将不胜感激。

感谢

假设ps是你的粒子系统,你可以像这样启动和停止它:

[ps resetSystem]; // starts, newly created effects are already running
[ps stopSystem];  // stops

等待10秒可以完成以10秒间隔调度选择器。

希望它能有所帮助:)

-(void)addParticles
{
  [particles resetSystem]; //restarts particles
}
-(void)playParticles //call this later somewhere in your code e.g in touches began [self playParticles];
{
  id playParticles = [CCCallFuncN actionWithTarget:self selector:@selector(addParticles)];
  id stopParticles = [CCCallFuncN actionWithTarget:self selector:@selector(stopParticles)];
  id wait = [CCActionInterval actionWithDuration:3];
  CCSequence *Particlesbegin = [CCSequence actions:wait,playParticles,wait,stopParticles, nil];
  [self runAction: Particlesbegin];
}
-(void)stopParticles
 {
  [particles stopSystem];
 }

//in touches began
if(CGRectContainsPoint(Btn.boundingBox, location))
{
    [self playParticles];
}

最新更新