拜托,我想问一下如何在 iOS /cocos2d 中启动粒子系统,让它运行一定的时间,比如 10 秒,然后让它停止。
一个小的代码片段或示例将作为指南将不胜感激。
谢谢
拜托,我想问一下如何在 iOS /cocos2d 中启动粒子系统,让它运行一定的时间,比如 10 秒,然后让它停止。
一个小的代码片段或示例将作为指南将不胜感激。
谢谢
假设 ps 是你的粒子系统,你可以像这样启动和停止它:
[ps resetSystem]; // starts, newly created effects are already running
[ps stopSystem]; // stops
等待 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];
}