1
votes

I'm trying to figure out how best to accomplish drawing a scene in an iphone app. Here is the situation:

  • I have a single view that I would like to draw to
  • I would like to have a background image
  • I would like to draw several different images on top of the background each which have separate transforms applied to them (rotation, scaling)
  • I would like to draw several blocks of text on top of the background image as well - I need to word break these as well as transform them (rotation, scaling)
  • I would like to animate these images and blocks of text being drawn on screen (I don't need to do this in the first iteration but I don't want to choose a path that will preclude me from doing this in the future.

I'm not really sure where to start - but because things aren't animated too much it doesn't seem like this has to be really performant so I'm thinking Quartz will be the way to go.

Some possible solutions I can think of:

  • Use quartz: Draw the background to a view's cgcontext. Create several CGLayers and draw the text/images to them. Transform the CGlayers (can you do this?) then draw the layers to the main CGContext.

  • use OpenGL: please no. unless I really need to.

Ideas?

Thanks.

2

2 Answers

1
votes

Mostly agree with Marco. CA is perfect for this work. Set up a view and add a bunch of layers.

A couple of points though.

You can directly draw text using the NSString UIStringDrawing category methods. works really well and don't have the overhead of UILabel.

Drawing with CoreGraphics is not too slow, because CoreAnimation intelligently caches the layer. That is, it's only drawn once and then CA animates a copy unless the layer is sent a setNeedsDisplay message.

1
votes

Use CoreAnimation CALayers for the imags (you can apply tranformations to them) and UILabels for the text. Drawing with CoreGraphics will be too slow for animating.