Sprite Lab Documentation

move  pixels  toward 
Category:Actions

Sprites moves a specified number of pixels towards a location.

Rather than specify an exact direction to move in, this block lets the sprite move towards a location. This can be useful when you want a sprite to target something or chase another sprite.

Examples

Example 1

No matter where the target is, the pick will always get a bullseye. Hold down the ‘t’ key to throw the pick to the target.

Example 2

The dog loves chasing the bone! Click and hold on the bone to drag it around the display, and hold down the spacebar to have the dog chase it.

Example 3

This project has the same function as the one above but uses the “chasing” behavior to automate the dog to chase the bone (and therefore doesn't use the move pixels toward block).

Syntax

moveToward

Parameters

NameTypeRequired?Description
sprite

The sprite or sprite group to move

number

The number of pixels the sprite is moving

location

The location that the sprite is moving toward

Found a bug in the documentation? Let us know at support@code.org.