cocos2d启动粒子从未来的特定时间 [英] cocos2d starting particles from a specific time in the future

查看:181
本文介绍了cocos2d启动粒子从未来的特定时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个具有空间背景的cocos2d应用程序,其中我利用一个CCQuadParticleSystem来做闪烁的星星。我已经使用ParticleDesigner生成了这个粒子系统。一旦我加载粒子系统,表示星星的白点开始出现在背景中,一段时间后,它们逐渐消失,这样,在粒子系统达到状态的几秒钟之后,充满了星星的夜空出来。



我的问题是,我想知道是否有一种方法使粒子系统从未来的特定时间开始(例如t0 = 3秒),因此我不必等待所有的开始闪烁。



我希望我已清楚解释这个问题。



提前谢谢。



我假设你使用某种类型的 updateWithDelta:

/ code>方法在游戏循环中更新粒子。

基于你的评论下面,我的方法还是不错,它只是需要一些调整。您只需要删除粒子系统上的 updateWithDelta:方法中的条件。



在.h文件中:

  BOOL particleShouldUpdate; 
float particleTimer;

init 方法中:

  particleShouldRender = NO; 
particleTimer = 3.0f;

updateWithDelta: p>

  if(!particleShouldRender){
particleTimer - = delta;
if(particleTimer< 0){
particleShouldRender = YES;
}
}
//更新你的粒子。

最后,在您的渲染方法中:

  if(particleShouldRender){
//渲染你的粒子。
}

注意要停止渲染,只需要像在 init 方法中那样重置2个变量,并且会产生相同的效果。



EDIT2: 进一步澄清后,我们只需要修改您的粒子的 init 方法。我将在这里做两个假设,你只需要稍微改变它们以适应你的需要。假设您的更新周期为每秒60帧,最小粒子寿命为1.01,并且在开始游戏之前需要3秒的更新。然后在 init 方法中,尝试:

  0.0f; delta< 3.0f; delta + =(1/60)){
[particle updateWithDelta:(float)(1/60)];
}

这将像通常那样更新你的粒子, ,并且在任何其他更新之前。或者,如果您担心更新粒子时的速度,可以尝试:

  for(int i = 0; i< ; 3; i ++){
[particle updateWithDelta:1];
[particle updateWithDelta:0.02];
}

这将更快,但可能有一些问题,取决于您的粒子参数。

所以进一步研究这个问题,cocos2D不允许你这样做。我在网上找到了一个类似问题,他们建议您使用 posVar speed ,使它们足够大,当你转换到场景,一旦你完全转换到场景,将值重置为正常。您可以试试看!



希望有助于!


I am developing a cocos2d based app with a space background in which I am exploiting a CCQuadParticleSystem to make blinking stars. I have generated this particle system with ParticleDesigner. As soon as I load the particle system white dots representing stars start appearing in the background and after a while they fade out so that, after few seconds in which the particle system reaches the regime state, a night sky full of stars comes out.

My problem is that I would like to know if there is a way to make the particle system starting from a specific time in the future (for instance t0 = 3sec) so that I do not have to wait to have all the starts blinking.

I hope I have clearly explained the problem

thank you in advance

Andrea

解决方案

I assume you are using some kind of updateWithDelta: method in your game loop in order to update the particles. If you want the particles to start after a certain interval, make your own timer.

Edit: Based on your comment below, my method is still good, it just needs some tweaking. You need only remove the condition in the updateWithDelta: method on the particle system. That way, it will still update for those 3 seconds, but will not render, and therefore look the way you are describing.

In the .h file:

BOOL particleShouldUpdate;
float particleTimer;

In your init method:

particleShouldRender = NO;
particleTimer = 3.0f;

In your updateWithDelta: method:

if(!particleShouldRender){
  particleTimer -= delta;
  if(particleTimer < 0){
    particleShouldRender = YES;
  }
}
// update your particle.

Finally, in your render method:

if(particleShouldRender){
  // render your particle.
}

Note that from this point, if you want to stop it rendering, you need only reset the 2 variables like as in the init method, and the same effect will occur.

EDIT2: Upon further clarification, we only need to adapt the init method of your particle. I will make 2 assumptions here, and you need only change them slightly to fit your needs. Suppose that your update cycle is 60 frames per second, the minimum particle lifespan is 1.01, and that you want 3 seconds of updates before you start the game. Then in the init method, try:

for(float delta = 0.0f; delta < 3.0f; delta += (1/60)){
  [particle updateWithDelta:(float)(1/60)];
}

This will update your particle like it normally would, but without rendering at each interval, and before anything else gets updated. Alternatively, if you are worried about speed when updating your particle, you can try:

for(int i = 0; i < 3; i++){
  [particle updateWithDelta:1];
  [particle updateWithDelta:0.02];
}

This will be faster, but may have a few issues depending on your particles parameters.

EDIT3: So looking into this further, cocos2D does not let you do this for some reason. I found a similar question online to this, and they suggested you play with the posVar and speed to make them large enough while you are transitioning into the scene, and once you have fully transitioned into the scene, reset the values to normal. You may want to give that a try!

Hope that Helps!

这篇关于cocos2d启动粒子从未来的特定时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆