Game Development Reference
In-Depth Information
Listing 8-22 shows the rotationGesture : task for the class RotationGestureController . In this
task, we perform the now familiar tasks based on the state of the rotationRecognizer . If the state
is UIGestureRecognizerStateBegan , we simply record the starting rotation of actor Viper. If the state
is UIGestureRecognizerStateChanged , we get the rotation value from rotationRecognizer . The value
of rotation is relative to where the user first placed his or her fingers. Since the value of rotation is
relative to startRotation , we have to add rotation to startRotation to have the ship turn like a knob.
We multiply the rotation by 2.0 to make the rotation faster and more responsive. This is only done
because we might use this technique in an action game, where we want the user to be able to rotate
the ship pretty quickly. Once the value of finalRotation is calculated, we see if it is bigger or smaller
than the current rotation. This allows us to set the state of Viper to either VPR_STATE_CLOCKWISE
or VPR_STATE_COUNTER_CLOCKWISE.
When the gesture is over, we simply set the state of Viper back to VPR_STATE_STOPPED.
Additionally, if the gesture was cancelled, we reset the rotation of the ship back to the
startRotation .
The next example is more similar to the tap example than to the previous example because it
handles what it is called a long press.
Long Press Gesture
The long press gesture is a gesture where the user touches a point on the phone and holds it for a
bit. It is sort of like a tap, but longer—as the name implies. Users often invoke the long press gesture
when they want to rearrange their apps; when you press an app to make them all start shaking, it is
a long press. You also use a long press when pressing a key on the keyboard that has sub-items.
For example, open Safari and tap on the address field. Once the keyboard shows up, put your finger
on the “.com” button. After a moment, five alternative top-level domains are displayed. For this
example, we are going to combine taps with long presses to change which size bullet a spaceship
fires, as shown in Figure 8-6 .
 
Search WWH ::




Custom Search