views:

25

answers:

1

Hi all,

I currently have a game which uses one single UIView to draw a number of sprites onto the screen in its drawrect method every game tic. I have been advised that for performance it would be better to separate out each sprite into it's own UIView.

My questions are :

  • Structurally how does this work ? Do I create one UIView and then add further UIViews as a subview ?
  • Should the gamecontroller call one UIView and then that UIView call the next ? Or should it return to the game controller.

Many thanks in advance,

Martin

+1  A: 

You might want to consider using CALayers instead of UIViews if you are going to create a bunch of separate containers, they will be faster for core animation operations etc.

If you use UIViews you would have one parent view then add your others as subviews to that, if you use CALayers you would add your layers as sublayers to the main view.layer.

Ben
Thanks Ben. So with a CALayer would you just pass data from the gamecontroller in the same way ? So you'd feed in the x co-ordinate for where the sprite should move and use core animation to move to that point ? If I use UIViews - how do I add the subviews - would I use "addsubview" in the first UIView ?
Ohnomycoco
Yes use addSubView to add sub views to a parent view and addSublayer to add sub layers to a parent layer. Either should work, but CA will be more optimized if you directly use layers.
Ben