Now that we have a level, we need to add a turret. Double-click on the background, select add sprite, and then add the graphic. Make sure that the dimension of this graphic is 32
by 32
; everything that we had set up earlier needs to be on this grid. Your playing area should look like the following screenshot:
First, we will add some functionality using the following steps:
PlaceTurret
object, as shown in the following screenshot: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:
3.142.255.140