Reputation: 6346
In my iPhone app, I need to show a large number (max 150) of small dots of 10x10 pixels that move around the screen individually. They don't need to move smoothly in any way, but need to be updated every second or so. Currently I have that implemented as a single CALayer that I redraw every second.
But I understand that CALayers are very efficient because they are mapped to the GPU hardware. So I wondered if it would be more efficient (in terms of battery usage) to create a separate CALayer for each dot and move that by setting their position properties.
So I wonder whether you have experience with that. The CPU would have less to do, but the GPU more. How many CALayers can still be handled by the GPU hardware?
If I make them separate CALayers, I could also easily animate them, which would look much better. Would that be a lot more energy intensive?
What makes it worse in my case, is that I currently use a CATiledLayer for them, with a maximum of 4 tiles that are exposed. That also means I need to redraw them 4 times each update.
Upvotes: 2
Views: 1523
Reputation: 21
there. I have met similar problem as you did. In my case, I was drawing 80 or so bar risers in a bar chart. Previously, we use a UIView (with its drawRect implemented) for each riser, and later I decided to use CALayer (without implementing its drawLayerInContext) for each of them for animation. with the bar number as 80, I found 1. UIView method consumes more memory(as it request cgcontext in drawRect). 2. UIView method has better animation responsiveness. In my case, the UIVE FPS is about 60, but the CALayer is about 34.
Later, I tried a case with less bar number (40, 30, etc), the GPU is less stressed, and I can get the satisfied FPS number from CALayer animation.
What I want to mention here is when you switch to "one layer per dot", you need to check out if the animaiton is as smooth as before.
Upvotes: 2