Game Development Reference
In-Depth Information
We want to create a turret object on layer 1. Remember that layer 1 is the player layer—if
we spawn it on layer 0, it will be beneath the player layer and we would not be able to see
the turrets. We also need to add some code. This will make sure that the turret snaps to the
grid. As you can see in the following screenshot, the numbers are related to 32, which is
our grid size:
For the next part, we need to do a little bit of math. Doing so will snap the turret to the
grid. The numbers represent a grid of 32 by 32. We are adding X and Y values because we
need to snap to an X and Y position. You need to add the following code to your project:
round((Touch.X-16 /32) * 32 + 16)
round((Touch.Y-16 /32) * 32 + 16)
Your project should have the following elements:
Now, it's time to test our game. Press F5 and then try it out. It should look something like
the following screenshot:
Search WWH ::




Custom Search