Follow the Pointer

In this chapter, we will get a big spiky ball to follow the mouse around the screen. Later on, you'll use the ball to pop some bloons!

Add Background

First, let's make the scene pretty.

Add the monkey_lane asset to the game. Try to position it in the top-left corner, so it will fill the whole game screen.

Add Layers

Now let's make sure our game objects appear above the background. It wouldn't do to have everything occur underground.

Create a new layer. This will be home for our big spiky ball. Name it something like "Big Spiky Ball" (the exact name doesn't matter, so long as you know what it means).

Add Big Spiky Ball

Create a big spiky ball. Really it can be any asset, but we will assume it is a big spiky ball.

Script Big Spiky Ball

Now we're going to make the big spiky ball follow the mouse. We're also going to tag the ball, so other game objects can recognize it.

We're going to offset the ball a little bit, so its center is on the mouse pointer. If we didn't do this, the mouse would correspond to the top left corner of the ball. This looks a little funny, so we don't do it.

Right-click on the big spiky ball and select Add Script.

  • Name the script "Ball".
  • Create a When created event block.
    • Add the Add tag... on myself sensing block.
      • Set the tag text to "Ball". We will use this tag later, so if you're not using a big spiky ball, be careful.
  • Create a Constantly event block.
    • Add the Set x position of myself to: transform block.
      • Create the following blocks and leave them loose for now:
        • X position of mouse sensing block
        • Actual width of myself transform block
        • - operator block (subtraction)
        • / operator block (division)
        • 2 operator block (just a number)
      • Fill out X position to X position of mouse - ( Actual width of myself / 2 ). Be sure that the division operation is innermost so it happens first.
    • Duplicate and add the transform block.
      • Change X to Y (be thorough - X appears in two places).
      • Change Width to Height.

Complete Big Spiky Ball script

Play Game

Now save and test your game. You should see a big spiky ball following your cursor around the screen. It sure looks like it could pop a few bloons!

Well, let's make something to pop.

results matching ""

    No results matching ""