Game Development Reference
In-Depth Information
Rotating the cannon
Now, we are ready to make our game. Let's go to the event sheet and add an
Every Tick
event by navigating to
System
|
Every Tick
. Once you have added that, add an action. In
this case, it's going to be for the cannon sprite and the action should be
Rotate toward pos-
ition
. Check the following screenshot:
We are going to rotate the cannon with the mouse. Luckily, this is really easy to do in Con-
struct 2.
Let's move the cannon by 10 degrees (this is the speed at which the cannon rotates). In the
X
box, type
mouse.x
and type
mouse.y
in the
Y
box. This will rotate the cannon to the
position of
Mouse.X
and
Mouse.Y
, or simply the mouse position. This is shown in the
following screenshot:
Run the game and test it out. It is good to test early and often. Make sure you save often as
well. You will notice that the cannon does not rotate the way we want it to—the reason is
that the cannon rotates around
Origin
. Let's double-click on the cannon and move
Origin
closer to the back of the cannon. Run the game again to test it.