Search code examples
iphoneuiviewquartz-2d

Splitting one main UIView into Multiple UIViews for Sprite Drawing (Quartz 2d)


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


Solution

  • 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.