Skip to content
https://storage.googleapis.com/files.cs-first.com/game-design/game-icon%402x.png

2. Following the Mouse Pointer

Transcript

In this video you will program the player sprite to follow the mouse pointer.

To start, select the players sprite.

Next, click the motion menu and drag out a go to mouse pointer block.

When you click it the sprite will go towards the mouse pointers location.

The sprite needs to follow the mouse.

That means that the sprite needs to go to the mouse pointer over and over again.

Not just once.

To do that, use the forever block.

Now when you click on this block stack the sprite will go to the mouse every time.

Good.

Next, add an event to tell the computer when to run this code.

Use a when sprite clicked event which tells the sprite to follow the mouse pointer when the sprite is clicked.

Great.

Finally, try it out to see if it works.

Click the sprite.

Don't click and drag the sprite, but instead click and release it.

To stop the program click the stop sign.

Nice job.

Now it's your turn.

Program your player sprite using: a go to mouse pointer block, a forever block, and a when this sprite clicked event.

Instructions

  1. Make the sprite follow the mouse pointer.
  2. Make the sprite follow the mouse pointer forever.
  3. Make the sprite follow the mouse pointer when the sprite is clicked.