Game Development Reference
In-Depth Information
Create a new rule and name it ''Setting the Weight.'' The conditions for this rule
''Attribute'' ''gameInMovement'' is ''false''
''Actor receives event'' ''touch'' is ''pressed''
Those conditions will ensure that you can only move the weight when the
metronome is off.
Drag and drop two Constrain Attribute behaviors into the rule and change:
Weight.Position.X to 160
Weight.Position.Y to max(120,min(340,
The last constrain will ensure that the weight is positioned where your finger
touched the screen within the limit of 120 to 340.
Drag and drop a Constrain Attribute behaviors into the rule and change:
Weight.InitY to Weight.Position.Y
This will ensure that InitX and InitY always contain the last position of the weight
before pressing the On button. You will use this information to calculate the
movement and to return the weight to its position when you press the Off
Last but not least, use the position of the weight to determine the speed of the
metronome. The higher the weight is, the faster the pendulum will go. Use the
formula precision(120/Weight.Position.Y),2). Precision function will help you to
keep only two digits below the second.
Drag and drop another Constrain Attribute into the rule and change:
game.speed to precision(120/Weight.Position.Y),2)
Your Weight Setting rule is shown in Figure 10-21.
Search WWH ::

Custom Search