Game Development Reference
In-Depth Information
Moving the Paddle with the Accelerometer
To followfrom this point, you can simply open the file BreakaWall-
step2.gameproj .
Let's have some fun! In order to move the racket, you will use the built-in
accelerometer of the iOS device. In order to create such a feature, you will again
use the device attributes, especially the accelerometer. In fact, you will need to
use detection on the X-axis of the accelerometer.
Open the Racket actor in the Actor Editor. In the left movement rule, add a new
condition. The condition is ''Attribute''''game.accelerometer.X''''<''''-0.05''. You
also need to change from ''All'' to ''Any'' in ''When 'Any' conditions are valid.''
That's it! Your new rule will be similar to Figure 4-19.
This implementation of the movement based on the accelerometer is rough at
this stage and does not take into consideration any amount of tilt in the
movement. It is only a first approach. You will learn a more advanced approach
in Chapter 8.
Figure 4-19. Left Movement rule with the accelerometer
The Accelerometer
The accelerometer is measuring the device's own acceleration in the
3-D space. Sensors in your iOS device capture every movement and
tilt so it can calculate the orientation of the device and many other
usages (such as which direction the device is moving).
 
Search WWH ::




Custom Search