IPhone. Particle System Performance

I am trying to use rain and snow as a particle system using Core Graphics . In the simulator, rendering continued fine, but when I run my application on a real device rendering, it slows down.

So, advise me, please, approaches to increase the performance of the particle system drawing on the iPhone .

Maybe I should use OpenGL for this or CoreAnimation ?

+2
source share
3 answers

OpenGL will be the lowest level for rendering, so it should provide maximum performance (if everything is done correctly). CoreAnimation will be close enough if there are not so many particles (the exact figure depends on other factors, but up to about 50 should be fine). When you say you're using CoreGraphics, do you mean at the moment that you are redrawing by timer? If so, then CoreAnimation will definitely help you - as long as you can split each particle into a view. You can still use CoreGraphics to render individual particles.

Do you use a physics engine to calculate positions?

+2
source

If you simply draw a view using Core Graphics, and then redraw it in each frame to reflect the movement of particles, you will see terrible performance (see this answer for details). You will want to upgrade to OpenGL ES or Core Animation to animate a particle system.

My recommendation is to look at CAReplicatorLayer , a new type of Core Animation layer added in iPhone OS 3.0 and Snow Leopard. I have seen some impressive particle systems created only using this type of single layer, without using a lot of code. See the ReplicatorDemo sample application (for Mac, but the basic concepts are the same), or Joe Ricioppo See article 1e100f and outside the CAReplicatorLayer page .

+2
source

It is hard to give advice with little information about your implementation. One thing that is the main bottleneck on the iPhone from my experience is memory allocation. Therefore, if you select new objects for each generated particle, this will be the first thing you might want to fix. (Highlight the pool of objects and reuse them.)

+1
source

Source: https://habr.com/ru/post/1380610/


All Articles