views:

733

answers:

2

Hi all,

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.

+1  A: 

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.

Marco Mustapic
+1  A: 

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.

Kailoa Kadano
So in the meantime, before animation, should I just use CGLayers? Also - whats the difference between CoreGraphics and CoreAnimation? Are they both part of Quartz? I'm having trouble distinguishing between the different names....Anyone have any good resources for CoreAnimation/CALayers/CGLayers?
aloo
CGLayers are part of Core Graphics. CALayers are part of Core Animation. Neither is part of the other, but one may presume that Core Animation uses Core Graphics under the hood. The difference is that Core Animation is designed to make it easy for you to animate things, whereas Core Graphics is designed only for you to draw graphics.
Peter Hosey
Great thanks. Got this working.
aloo