How to use it#
- Set the screen width and height to match your game, and choose the grid spacing.
- Move the pointer over the screen: the position appears in the side panel, exactly as
pygame.mouse.get_pos()would report it. - In Place points mode, click to add points. In Draw a Rect mode, drag to create a rectangle and read its attributes.
- Copy the generated Python to draw your points and rectangle in Pygame.
With the canvas focused, the arrow keys move a crosshair one pixel at a time (Shift moves one grid cell) and Enter places a point.
How Pygame coordinates work#
- The origin
(0, 0)is the top-left corner of the window. - x increases to the right; y increases downward. Moving "up" means subtracting from y.
- Positions are measured in pixels. In a 640 × 480 window, the bottom-right pixel is
(639, 479). - Coordinates outside the window are allowed. Things drawn there are simply not visible, which is handy for objects entering from off-screen.
Rect attributes#
A pygame.Rect(x, y, width, height) has many named positions. For Rect(100, 50, 200, 80):
| Attribute | Value |
|---|---|
topleft | (100, 50) |
topright | (300, 50) |
bottomleft | (100, 130) |
bottomright | (300, 130) |
center | (200, 90) |
right, bottom | 300, 130 |
right and bottom are one pixel past the rectangle's last pixel column and row. Assigning any attribute moves the rect, for example rect.center = (320, 240) centres it in a 640 × 480 window. More in the Rect reference.
Angles and maths#
Because y points down, angles measured with standard maths functions appear to go clockwise on screen. The pygame.math reference explains how this affects rotations.