Question

What should be the difference, purpose wise, between these two methods in my render loop?

Apple has this to say....

About update() The view controller calls its delegate’s glkViewControllerUpdate: method. Your delegate should update frame data that does not involve rendering the results to the screen.

About drawInRect: the GLKView object makes its OpenGL ES context the current context and binds its framebuffer as the target for OpenGL ES rendering commands. Your delegate method should then draw the view’s contents.

So basically, when I create a GLKView in my view controller, that controller becomes the delate, so I am looking at these methods side by side.

I assumed that update() should contain any transforms or other logic.

Was it helpful?

Solution

In the first instance, Apple are trying to help you decouple timing from frame rate. If your game always manages to draw a frame in the time allotted for a single frame, the two will occur in lockstep. But even if lots of objects come on screen and your frame rate sags a little, you'll still get the same number of updates a second so objects will still move at the same speed.

In the second, they're helping you keep your code divided as model-view-controller. How your objects are presented should be decoupled from how they act.

So your update should progress whatever it is that causes your animation, your draw should present the current state.

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