Skip to content

Canvas

Type key: CANVAS

Rotation in degrees, clockwise. Type float, default 0.

Background color of the scene. Type (r, g, b, a), default (0, 0, 0, 255).

Name shown in the Hierarchy panel. Read-only at runtime. Type str.

Angular velocity damping. Type float, default 0.

Bounciness (0 = fully inelastic, 1 = fully elastic). Type float, default 0.2.

Whether the rigid body is simulated. Type bool, default False.

Keep the rotation fixed (collisions do not spin the object). Type bool, default False.

Friction coefficient. Type float, default 0.6.

Gravity multiplier (0 = unaffected by gravity). Type float, default 1.

Linear velocity damping. Type float, default 0.

Mass. Type float, default 1.

Size of the rect/ellipse body shape (0 = use the object’s own size). Type float, default 0.

physics_shape_offset_x, physics_shape_offset_y

Section titled “physics_shape_offset_x, physics_shape_offset_y”

Shift of the body shape away from the object centre. Type float, default 0.

Vertices of a polygon body shape. Type list, default [].

Body shape: 'rect', 'ellipse' or 'polygon'. Type str, default 'rect'.

Rigid-body type: 'static', 'dynamic' or 'kinematic'. Type str, default 'dynamic'.

Transform anchor mode, see set_pivot(). Type str, default 'center'.

Coordinates of a 'custom' anchor (in the object’s own pixel grid, origin at its top-left). Type float, default 0.

(x, y); assigning it updates x and y too. Type (int, int), default (20, 20).

(scale_x, scale_y). Type (float, float), default (1, 1).

Stretch factors (1 = original size). Type float, default 1.

Path of the attached script, relative to the project. Type str, default ''.

(width, height). Type (int, int).

Type key; the canvas is CANVAS. Read-only at runtime. Type str.

Unique id, used by get_object_by_uuid(). Read-only at runtime. Type str.

Hidden objects are not drawn and cannot be clicked. Type bool, default True.

Size of the canvas in pixels; the editor keeps it at the project’s window size. Type int, default = the screen size.

Position relative to the parent object (the canvas itself is at 0, 0). Type int, default 20.

Distance from the object’s centre to a point.

  • x (int): point x, in scene coordinates.
  • y (int): point y, in scene coordinates.

Distance between two object centres.

  • other (object): the other object.

Rotation in degrees.

Centre of the object (scene coordinates).

Fill, text or tint color as (r, g, b, a).

Unit vector (dx, dy) pointing from the object to a point.

  • x (int): point x, in scene coordinates.
  • y (int): point y, in scene coordinates.

Height in pixels.

The name of the object.

Transform anchor mode (e.g. 'center', 'top_left', 'custom').

The anchor resolved to content pixels (x, y).

Local position (x, y), relative to the parent object.

Local pygame.Rect of the object.

The stretch factors as (scale_x, scale_y).

The x stretch factor.

The y stretch factor.

Size in pixels as (width, height).

The type key of the object.

The uuid of the object.

The visible state as a bool.

Width in pixels.

Position in scene coordinates, i.e. with every parent offset added.

pygame.Rect in scene coordinates.

The x part of the local position.

The y part of the local position.

Makes the object invisible. Same as obj.visible = False.

True while the object is hidden.

Cheap test: True when the point is inside the object’s bounding box.

  • x (int): point x, in scene coordinates.
  • y (int): point y, in scene coordinates.

Pixel-perfect test: True only on a non-transparent pixel. Prefer it for clicks, not for per-frame checks.

  • x (int): point x, in scene coordinates.
  • y (int): point y, in scene coordinates.

Same as is_visible().

True while the object is visible.

Moves the object by (dx, dy) pixels; on the canvas this moves the whole scene.

  • dx (int): horizontal delta.
  • dy (int): vertical delta.

Sets the rotation.

  • degrees (float): angle, clockwise.

Sets the centre (scene coordinates).

  • x (int): new centre x.
  • y (int): new centre y.

Sets the color.

  • color ((r, g, b, a)): the new color tuple.

Sets the height.

  • h (int): new height in pixels.

Choose the transform anchor.

  • pivot (str): 'center' (default), 'top_left', 'top_center', 'top_right', 'center_left', 'center_right', 'bottom_left', 'bottom_center', 'bottom_right' or 'custom'.

Rotate/scale around a free point of the object’s own pixel grid (also sets pivot to 'custom').

  • x (float): anchor x in the pixel grid.
  • y (float): anchor y in the pixel grid.

Sets the local position.

  • x (int): new x, relative to the parent object, in pixels.
  • y (int): new y, relative to the parent object, in pixels.

Sets both stretch factors.

  • sx (float): x stretch factor.
  • sy (float): y stretch factor.

Sets the x stretch factor.

  • sx (float): x stretch factor.

Sets the y stretch factor.

  • sy (float): y stretch factor.

Sets the size in pixels.

  • width (int): new width.
  • height (int): new height.

Sets the visible state.

  • visible (bool): True shows the object, False hides it.

Sets the width.

  • w (int): new width in pixels.

Sets the position in scene coordinates.

  • x (int): new x, in scene coordinates.
  • y (int): new y, in scene coordinates.

Sets the x part of the local position.

  • x (int): new x, relative to the parent object.

Sets the y part of the local position.

  • y (int): new y, relative to the parent object.

Makes the object visible. Same as obj.visible = True.

Pressed and released on the object.

When the scene is replaced or the game closes.

Double click on the object.

Pointer moves while dragging.

  • pos ((int, int)): pointer position in scene coordinates.

The drag ends.

A pointer drag on the object starts.

Pointer moves onto the object.

Pointer moves off the object.

Left button pressed on the object.

The button that was pressed on this object is released.

Right click on the object.

Once, when the scene has loaded.

Every frame.

  • dt (float): seconds since the last frame.

When the object is shown or hidden.

  • visible (bool): True when shown, False when hidden.