Drawing particles

One part of my application shows the landscape, but right now it's a little boring. Therefore, I plan to revive some particles on the screen (think of something like tiny wings - http://www.youtube.com/watch?v=DpmcX-rWGfs ). However, I have not yet found an embedded particle system; How can I use this memory efficiently? I have already implemented my own animation system for some clouds that enliven the landscape using CADisplayLink, and this seems to be sluggish (although I hope to make it faster soon). Another very heavy system, for example, animating 20 small points at a time, is likely to break it.

+8
objective-c iphone core-animation particles
source share
4 answers

I haven't found an embedded particle system yet,

There are several β€œfree” projects in which particle systems are built in. You can visit this video tutorial for a particle system that will be more than effective enough for the needs you are talking about. This way of creating a particle system is basically the same as using Cocos2d, so follow the tutorial and then upload the project files, you can easily insert your particle emitter into your project.

How can I use this memory efficiently?

I would recommend you use the Object Pool Pattern, "you basically define a pool of particles, say 1000 objects. Then your emitters, ask for a pool of particles when they need them. If the pool is empty, you can manage the case accordingly. It can seem inefficient in terms of memory, but it is very efficient performance (to avoid the real-time distribution of many small objects such as particles).

Some sentences, when you declare your particle structure, try to be light and aligned in degrees 2 (this will make your structure more cache friendly), this is 32 bytes:

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; }; 

But depending on your needs, it can be much less, maybe you do not need color / index / etc. You must evaluate it yourself.

Finally, I would recommend you take a look at the CCParticleSystem class, you can download the code here . Their implementation is not so easy, but rather flexible and can achieve very pleasant effects.

Good luck with your particles :)

+4
source share

You should check out the new iOS Recipes book written by Matt Drance:

http://pragprog.com/titles/cdirec/ios-recipes

Among recipes, you can use the built-in CoreAnimation CAReplicatorLayer to create an emitter in Build a Simple Emitter.

The book is still in alpha, but if you buy it, you will receive updates upon completion.

+4
source share

Cocos2D is a 2D graphics engine that uses OpenGL ES 1 for rendering. It comes with an integrated particle system. The particle engine code is pretty simple. It uses VBO to draw textured quads for particles. You must be able to adapt this to your own needs.

+4
source share

If you want to target on iOS5 and higher, you can use the built-in OS tools, which are CAEmitterLayer.

0
source share

All Articles