Game Development Reference
In-Depth Information
Figure 6-12. Touch rule
Return to the Scene Editor. Drag and drop the projectile on the scene and
position it between the two arms of the slingshot.
Hit the Preview button and play around with the projectile.
Throwing the Projectile
The next step is to be able to throw the projectile when you remove your finger
from the screen. The power will be defined based on the distance between the
point of origin and the pullback, and the direction will be from vectorToAngle.
You will use the Change Velocity behavior to set the direction and the speed of
the projectile once you release the touch.
Intuitively, you might think to use a new rule with the condition ''Actor receives
event'' ''touch'' is ''released.'' This approach is OK while you remain within the
circle restriction, but if you go out of the circle and release the touch, it won't
work. Instead, you will use a small trick with an attribute and the existing Touch
rule. Create a Boolean actor attribute that is false by default. Then, once the
Touch is pressed, change the attribute to True. In the Touch rule, add a sub-rule
in the Otherwise section. The sub-rule condition is that the attribute is True. This
will avoid the possibility of the projectile being thrown before Touch is pressed.
 
Search WWH ::




Custom Search