cocos2d 从未来特定时间开始粒子
我正在开发一个基于 cocos2d 的具有太空背景的应用程序,其中我利用 CCQuadParticleSystem 来制作闪烁的星星。我用 ParticleDesigner 生成了这个粒子系统。一旦我加载粒子系统,代表星星的白点就开始出现在背景中,过了一会儿它们就会消失,这样,在粒子系统达到状态状态几秒钟后,就会出现充满星星的夜空。
我的问题是,我想知道是否有一种方法可以使粒子系统从未来的特定时间(例如 t0 = 3 秒)开始,这样我就不必等待所有的开始都闪烁。
我希望我已经清楚地解释了这个问题,
提前谢谢你
安德里亚
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我这样做了,结果完全按照我想要的方式工作。
I did this and it worked exactly the way I wanted it to.
你有没有尝试过
,好吧,虽然它可能滥用了 API 的初衷,但很有用
如果您有多个此类延迟反应,请注意 onStallComplete 中的重新进入。
注意:SO 新手,希望代码片段看起来正确
Have you tried a
ok, granted it is probably abusing the original intent of the API's , but is useful
watch for re-entrancy in onStallComplete if you have multiple such delayed reactions.
note: newbie at SO, hope the code snippet comes out looking right
我假设您在游戏循环中使用某种
updateWithDelta:
方法来更新粒子。如果您希望粒子在一定时间间隔后启动,请创建自己的计时器。编辑:根据您下面的评论,我的方法仍然很好,只是需要一些调整。您只需删除粒子系统上的
updateWithDelta:
方法中的条件即可。这样,它仍然会更新这 3 秒,但不会渲染,因此看起来像您所描述的那样。在 .h 文件中:
在您的
init
方法中:在您的
updateWithDelta:
方法中:最后,在您的渲染方法中:
注意 从这一点开始,如果你想停止渲染,只需要像
init
方法中那样重置2个变量,就会出现同样的效果。EDIT2:经过进一步说明,我们只需要调整粒子的
init
方法即可。我将在这里做出两个假设,您只需稍微更改它们即可满足您的需求。假设您的更新周期为每秒 60 帧,最小粒子寿命为 1.01,并且您希望在开始游戏之前有 3 秒的更新。然后在init
方法中,尝试:这将像平常一样更新您的粒子,但不会在每个间隔以及其他任何内容更新之前进行渲染。或者,如果您担心更新粒子时的速度,您可以尝试:
这会更快,但可能会出现一些问题,具体取决于您的粒子参数。
EDIT3:所以进一步研究一下,cocos2D 出于某种原因不允许你这样做。我在网上发现了一个类似的问题,他们建议你玩 < code>posVar 和
speed
以使它们在您过渡到场景时足够大,并且在完全过渡到场景后,将这些值重置为正常。您可能想尝试一下!希望有帮助!
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:
In your
init
method:In your
updateWithDelta:
method:Finally, in your render method:
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 theinit
method, try: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:
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
andspeed
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!
我认为没有办法让你的粒子系统快进 3 秒到未来。或者,我可以根据您的情况想象两种不同的解决方案:
I do not think there is a way to fast forward your particle system 3 seconds into the future. Alternatively I can imagine two different solutions depending on your circumstances:
我想不出直接实现这一点的方法,但是你可以尝试这样的方法作为解决方法吗?恐怕由于其他错误,我还无法对此进行测试,但正在努力。
我真正担心的问题是场景中的其他项目的运行速度也会快 100 倍。这是一个问题吗?
I can't think of a way to implement this directly, but could you try something like this as a workaround? I'm afraid I haven't been able to test this yet due to other errors, but working on it.
The issue I do worry about is the other items on your scene would also run 100 times faster. Is that an issue?