Question

Using UIView and Quartz has proven to be too slow for my 2D game

Was it helpful?

Solution

In general in OpenGL, there are basically two ways to do "scrolling", i.e. shifting the displayed contents perpendicularly to the viewing direction:

  1. Adjust the viewing, in other words "move the camera", so that the contents shift.
  2. Move the contents directly, keeping the camera fixed.

These are of course totally equivalent, and the inverse of each other.

These both assume that you do complete re-draws of your scene for each frame. Scrolling in the more "classical" sense, by copying the contents of the frame buffer while offsetting by a (dx,dy) amount, is not a technique that is very suitable for OpenGL.

Basically, creating a scrolling image could be as easy as drawing a single textured quad, and then shifting the position of it for each new frame.

OTHER TIPS

How large are your images and how slow is too slow? Using a UIScrollView with a containing UIView whose content is drawn via Quartz, I've been able to smoothly scroll views up to 2000 x 2000 in size. If you aren't redrawing your image content every frame, but instead moving the position of your views and letting Core Animation do the rest, I bet that you'll be able to get the kind of performance you want without dropping down to OpenGL.

Most 2-D performance issues that I've seen result from people trying to do all their animation in drawRect, constantly redrawing their content. You want to draw once, and then just move the origin of the drawn view or layer around. The content of the view is cached as an OpenGL texture, so it becomes very efficient to animate around.

For 2-D work, I regard OpenGL as the last place to turn to after you've exhausted all other alternatives. It will take you much longer to do the same things that you can using simple UIViews and Core Animation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top