Game Development Reference
In-Depth Information
Now you want to be able to move Player 1's racket with a finger. Remember
that the racket is constrained on a specific horizontal value. It can only move up
or down. So you only have to work on the y-axis.
The trick is to detect the touch, to collect the value of the y-axis of the touch,
and to constrain the Racket actor to this value. To collect the value of the touch
position, you are going to use the mouse device.
The Mouse Device
The mouse special object is an object inside GameSalad in the
Devices category. The Devices category helps you to take advantage
of the hardware functionalities of iOS devices. Here you have access
to the accelerometer, screen, audio, clock, touch, and mouse features.
The mouse feature represents where you touch the screen and you
collect this information through the position attributes.
Still, there is something very important to do to make it work. The racket shall
not move outside of the visible area. You manage this point by only taking into
account the touch within the range of 60 and 260.
1. Create a new rule and name it Touch Detection.
2. Add the following condition: Actor receives event of touch inside
(you could replace ''inside'' with ''pressed'').
3. Add the two additional conditions:
Attribute, game.Mouse.Position.Y,>, 60
Attribute, game.Mouse.Position.Y, <, 260
4. Add a Constrain Attribute of Rack Player 1.Position.Y to
game.Mouse.Position.Y.
The completed rule should look like Figure 3-15.
Search WWH ::




Custom Search