Revision as of 02:01, 23 July 2023 by Cutebross260IsBack (talk | contribs) (updated image caption)

An XY grid.

Scratch determines where to display sprites through a coordinate system, or a mathematical grid of infinite values. It uses the Cartesian coordinate system in which on a two-dimensional plane, a point has two values to locate or reference its exact position.


Scratch's coordinate system uses 2 coordinates, "X position" and "Y position", to determine the location of a sprite on the stage. The "X position" value determines the horizontal location of the sprite and the "Y position" value determines the vertical location or height. The screen is a 480x360 rectangle with the origin in the center, such that the X position can range from 240 to -240, where 240 is the rightmost a sprite can be and -240 is the leftmost, and the Y position can range from 180 to -180, where 180 is the highest it can be and -180 is the lowest it can be.

Coordinates are, by convention, written as a pair (X, Y): for example, the center of the screen is (0, 0).

Note Note: In this system, (0, 0) is considered the center of the screen; unlike many popular coordinate systems such as Quartz 2D and the HTML5 canvas API, which use (0, 0) as the top-left or bottom-left corner. This point (0, 0) is called the Origin.

This is also called a Cartesian coordinate system, and is an essential part of elementary algebra. (Specifically, most equations and expressions in algebra can be graphed on the Cartesian plane so to produce various shapes. For example, a line defined as x = y will produce a diagonal line.)


The X position and Y position of a sprite can be determined, set, and changed by the following blocks:


Main article: Direction (value)

Direction is determined by a rotational number system. The direction 0 is straight up. Every 90 units are equivalent to a quarter turn, where +90 is 90 degrees clockwise and -90 is 90 degrees counter-clockwise. The diagram below shows how this works.

Direction Diagram.png

The direction never exceeds 180 or goes below -180; it is always (internally) kept within these limits with the function:

set [bounded direction v] to ((((old direction) + (179)) mod (360)) - (179))

However, it is usually more helpful to set the direction from 0° to 360°, purely for convenience.

Any direction is equal to 360° + the direction: 90° = 90° + 360° = 450°.

These are similar to polar coordinates, except rotated 90° counter-clockwise. A polar coordinate consists of an angle and the distance away from the origin.

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.