[英]Starting and stopping a particle system in cocos2d
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. 拜托,我想问一下如何在iOS / cocos2d中启动粒子系统,使其运行一定的时间(例如10秒),然后使其停止运行。
A little code snippet or example which will serve as a guide would be appreciated. 可以作为指导的一些代码片段或示例。
Thanks 谢谢
Assuming ps is your particle system, you can start and stop it like this: 假设ps是您的粒子系统,则可以像这样启动和停止它:
[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. 等待10秒可以安排一个间隔为10秒的选择器。
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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.