Reputation: 129
Please, I like to ask how I can start a particle system in iOS /cocos2d, make it run for a certain amount of time say 10 seconds and then have it stopped.
A little code snippet or example which will serve as a guide would be appreciated.
Thanks
Upvotes: 1
Views: 3410
Reputation: 577
Hope it helps :)
-(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];
}
Upvotes: 1
Reputation: 64477
Assuming ps is your particle system, you can start and stop it like this:
[ps resetSystem]; // starts, newly created effects are already running
[ps stopSystem]; // stops
Waiting for 10 seconds can be done scheduling a selector with 10 second interval.
Upvotes: 7