iPhone. Particle system performance

余生长醉 提交于 2020-01-24 17:27:05

问题


I try to draw rain and snow as particle system using Core Graphics. In simulator rendering proceeded fine but when I run my app on real device rendering is slow down.

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

May be I should use OpenGL for this or CoreAnimation?


回答1:


OpenGL would be the lowest level to drop to for the rendering, so should offer the best performance (if done right). CoreAnimation would be close enough if there are not too many particles (the exact figure depends on other factors, but upto about 50 should be ok). When you say you're using CoreGraphics at the moment do you mean you're redrawing based on a timer? If so then CoreAnimation will definitely help you out - as long as you can seperate out each particle into a view. You could still use CoreGraphics to render the individual particles.

Are you using a physics engine to calculate the positions?




回答2:


If you are simply drawing a view with Core Graphics, then redrawing it every frame to reflect the movement of the particles, you will see terrible performance (for more, see this answer). You will want to go to OpenGL ES or Core Animation for the particle system animation.

My recommendation would be to look at CAReplicatorLayer, a new Core Animation layer type added in iPhone OS 3.0 and Snow Leopard. I've seen some impressive particle systems created just using this one layer type, without using much code. See the ReplicatorDemo sample application (for the Mac, but the core concepts are the same), or Joe Ricioppo's "To 1e100f And Beyond with CAReplicatorLayer" article.




回答3:


It's hard to give advice with little to no information about your implementation. One thing that is a major bottleneck on the iPhone from my experience are memory allocations. So if you're allocating new objects for each particle spawned, that would be the first thing you might want to fix. (Allocate a pool of objects and reuse them.)



来源:https://stackoverflow.com/questions/2538248/iphone-particle-system-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!