cocos2d 从未来的特定时间开始粒子

cocos2d starting particles from a specific time in the future(cocos2d 从未来的特定时间开始粒子)

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

问题描述

我正在开发一个基于 cocos2d 的具有空间背景的应用程序,在该应用程序中我正在利用 CCQuadParticleSystem 来制作闪烁的星星.我用 ParticleDesigner 生成了这个粒子系统.当我加载粒子系统时,代表星星的白点开始出现在背景中,一段时间后它们会淡出,这样,在粒子系统达到状态状态的几秒钟后,就会出现满是星星的夜空.

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.

我的问题是我想知道是否有办法让粒子系统从未来的特定时间(例如 t0 = 3sec)开始,这样我就不必等待所有的开始闪烁.

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

提前谢谢你

安德烈亚

推荐答案

我假设您在游戏循环中使用某种 updateWithDelta: 方法来更新粒子.如果您希望粒子在某个时间间隔后启动,请制作您自己的计时器.

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.

根据您在下面的评论,我的方法仍然很好,只是需要一些调整.您只需在粒子系统的 updateWithDelta: 方法中移除条件.这样,它仍然会在这 3 秒内更新,但不会渲染,因此看起来就像您描述的那样.

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.

在.h文件中:

BOOL particleShouldUpdate;
float particleTimer;

在你的 init 方法中:

particleShouldRender = NO;
particleTimer = 3.0f;

在您的 updateWithDelta: 方法中:

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

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

Finally, in your render method:

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

注意,从这里开始,如果你想停止它的渲染,你只需要像 init 方法那样重置 2 个变量,同样的效果会发生.

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.

进一步澄清后,我们只需要修改你的粒子的 init 方法.我将在这里做出 2 个假设,您只需稍微更改它们即可满足您的需求.假设您的更新周期为每秒 60 帧,最小粒子寿命为 1.01,并且您希望在开始游戏之前进行 3 秒的更新.然后在init方法中,尝试:

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.

因此进一步研究,cocos2D 出于某种原因不允许您这样做.我在网上找到了一个类似问题,他们建议你玩posVarspeed 使它们在过渡到场景时足够大,一旦完全过渡到场景中,将值重置为正常值.您可能想尝试一下!

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!

希望有帮助!

这篇关于cocos2d 从未来的特定时间开始粒子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:cocos2d 从未来的特定时间开始粒子

基础教程推荐