Game Development Reference
In-Depth Information
z = acceleration.z;
NSLog(@"x = %f y = %f z = %f", x, y, z);
CGPoint center = CGPointMake(size.width/2.0 * x + size.width/2.0, size.height/2.0 * y + size.
height/2.0);
[viper setCenter:center];
}
In Listing 8-36, we simply get the X, Y, and Z values from the UIAcceleration acceleration.
These values range from −1.0 to 1.0, based on the orientation of the device. Because the X value
corresponds to the device being tilted left or right (in portrait), we can simply use the value of X to
specify the X value of our new center value. We do the same for the Y value, and set the center
property of Viper.
This is a very simple example, but I hope it will get you headed down the right track. It seems to me
that getting basic functionality working is pretty simple, as in this example, but getting more complex
user interactions just right is considerably more work. I recommend reading the document entitled
“Event Handling Guide for iOS ,” which is available at http://developer.apple.com .
Summary
In this chapter, we explored how to respond to basic touch events. We also looked at how the
subclasses of UIGestureResponder can be used to interpret those touch events as concise gestures,
such as pinches, long presses, rotations, and more. In the last section, we looked at two ways to
use the accelerometer to control game actors. The first method allowed us to simply respond to a
shake event. The second technique showed how we could get direct access to accelerometer data
to control our application, laying the groundwork for motion-based gestures more complex than a
simple shake.
 
Search WWH ::




Custom Search