Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I have not yet found any built-in particle system;</p> </blockquote> <p>There are several "Free" projects that embed particle systems out there, you can visit this <a href="http://www.71squared.com/2009/05/iphone-game-programming-tutorial-8-particle-emitter/" rel="nofollow">video tutorial</a> for a Particle System that will be more than efficient enough for the needs that you mention. That way of making a particle system is basically the same way that Cocos2d is using, so watch the tutorial, and then download the project files, you can easily embed their Particle Emitter in your project.</p> <blockquote> <p>How can i do this memory-efficiently?</p> </blockquote> <p>I would recommend you using the "<a href="http://en.wikipedia.org/wiki/Object_pool_pattern" rel="nofollow">Object Pool Pattern</a>", basically you preallocate a "Pool" of particles, let's say 1000 objects. Then your emitters, ask the pool for particles when they need them. If the pool get's empty you can manage the case accordingly. This may not look efficient from a memory perspective, but it's very efficient performance wise ( to avoid real time allocation of many small objects like particles ).</p> <p>Some suggestions, when you declare your particle structure try to be lightweight and aligned to powers of 2 ( this will make your structure more cache friendly ), this one is 32 bytes:</p> <pre><code>struct Particle { CGPoint position; CGPoint speed; float life; float decay; unsigned short index; unsigned char color_R; unsigned char color_G; unsigned char color_B; unsigned char color_A; unsigned char rotation; }; </code></pre> <p>But depending of your needs, this could be much smaller, maybe you don't really need color/index/etc. You will have to evaluate that yourself.</p> <p>Finally I would recommend you to take a look at cocos2d <code>CCParticleSystem</code> class, you can download the code <a href="http://cocos2d-iphone.googlecode.com/files/cocos2d-iphone-1.0.0-rc.tar.gz" rel="nofollow">here</a>. Their implementation is not that lightweight, but it's quite flexible and can achieve very nice effects.</p> <p>Good luck with your particles :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload