Coordinate System - Scratch Wiki (2024)

"X" redirects here.For the information about the social media site, see Scratch on Social Media#Twitter.

Scratch determines where to display sprites through the 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.

Contents

  • 1 Positions
    • 1.1 Blocks related to the X position
    • 1.2 Blocks related to the Y position
  • 2 Directions
  • 3 References
  • 4 See Also

Positions

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. Large sprites can be moved past the edge of the stage, but at least 15 pixels of the sprite always remain visible.[1]

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

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.)

Blocks related to the X position

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

  • (x position) — A Stage Monitor and reporter block that reports the value of a sprite's X position
  • set x to () — Sets the X Position of a Sprite to a value
  • go to x: () y: () — Sets the X and Y Position of a Sprite to a value
  • glide () secs to x: () y () — Glides a Sprite to a certain X and Y position
  • change x by () — Changes the X Position of the Sprite by a value
  • [ v] of ( v) — A block that reports the value of any sprite's X position, Y position, direction, costume/backdrop number, size, volume and variables

Blocks related to the Y position

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

  • (y position) — A Stage Monitor and reporter block that reports the value of a sprite's Y position
  • set y to () — Sets the Y Position of a Sprite to a value
  • go to x: () y: () — Sets the X and Y Position of a Sprite to a value
  • glide () secs to x: () y () — Glides a Sprite to a certain X and Y position
  • change y by () — Changes the Y Position of the Sprite by a value
  • [ v] of ( v) — A block that reports the value of any sprite's X position, Y position, direction, costume/backdrop number, size, volume and variables

Directions

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.

The direction never exceeds 180 or goes below -180; it is always (internally) kept within these limits. A similar way to clamp the direction would be:

set [clamped 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.

References

See Also

  • Mouse Position
  • Direction
  • Stage

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

Coordinate System - Scratch Wiki (2024)
Top Articles
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 6724

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.