Friday, March 30, 2012

Part 8: Touch Events and Movement

Now, it would be fun if our object could somehow move. That way, we would truly see the effect of adding lighting to the scene. What would also be fun is to add a touch event to start and stop the object from moving. The best part is that it's very easy to do with the UIKit's gesture recognizers. And yes, you can use them in the GLKView!

What we're going to do is that every time you double tap, it will either start or stop the cube from rotating. Here's a link to the project after adding Touch events and movement:

In the ViewDidLoad method, you need to add the gesture recognizer and set its parameters. Then, you need to set up the callback, or selector, so that you can decide what to do when the event actually happens.

If you want your cube to be rotating when the application starts, just set _autorotate = YES and _cursor = 0.1 in the ViewDidLoad method, and there you go!

No comments: