Game Development Reference
In-Depth Information
Implementing the Sliding Effect
To implement the sliding effect, you will need two actors. Basically, the first one
will register the finger movement and the second one will control the camera
based on the data collected from the first actor.
Touch Actor
The Touch actor will be used to register the finger movements. It will be made
invisible on the scene.
Create an actor named ''Touch.'' Drag and drop an instance of the Touch actor
on the scene and double-click the instance to open it in the Actor Editor. Click
the lock icon to unlock the instance.
Create a new rule with the condition ''Actor receives event'' ''mouse button'' is
''down.'' This will detect that the finger has been positioned on the screen.
Contrary to the previous chapter, you don't use Touch to detect the finger
touch. You do use the mouse button detection because this gives you the
possibility to detect the touch anywhere on the screen, not related to position of
the actor.
Then drag and drop a Change Attribute behavior into the rule and change
Touch.Position.X to Device.Mouse.Position.X. Then drag and drop a Constrain
Attribute behavior into the rule and change Touch.Motion.Linear Velocity.X to
10*(game.Mouse.Position.X -- Touch.Position.X). Those two behaviors will
ensure that as long as the finger is on the screen there is no inertia. It moves
with the finger.
Last, drag and drop a Constrain Attribute behavior into the rule and change
Touch.Motion.Linear Velocity.X to Touch.Motion.Linear Velocity.X*0.95. This last
behavior will make an inertia that will slow down by itself with the 95% reduction
(*0.95).
The rule is shown in Figure 7-42.
 
Search WWH ::




Custom Search