Arcade Package API

This page documents the Application Programming Interface (API) for the Python Arcade library.

For example code, see Example Code.

Window Commands

This submodule has functions that control opening, closing, rendering, and otherwise managing windows. It also has commands for scheduling pauses and scheduling interval functions.

arcade.close_window()[source]

Closes the current window, and then runs garbage collection. The garbage collection is necessary to prevent crashing when opening/closing windows rapidly (usually during unit tests).

arcade.create_orthogonal_projection(left, right, bottom, top, near, far, dtype=None)[source]

Creates an orthogonal projection matrix. Used internally with the OpenGL shaders.

Parameters
  • left (float) – The left of the near plane relative to the plane’s centre.

  • right (float) – The right of the near plane relative to the plane’s centre.

  • top (float) – The top of the near plane relative to the plane’s centre.

  • bottom (float) – The bottom of the near plane relative to the plane’s centre.

  • near (float) – The distance of the near plane from the camera’s origin. It is recommended that the near plane is set to 1.0 or above to avoid rendering issues at close range.

  • far (float) – The distance of the far plane from the camera’s origin.

  • dtype

Returns

A projection matrix representing the specified orthogonal perspective.

Return type

numpy.array

arcade.finish_render()[source]

Swap buffers and displays what has been drawn. If programs use derive from the Window class, this function is automatically called.

arcade.get_projection()[source]

Returns the current projection.

Returns

Numpy array with projection.

arcade.get_scaling_factor(window)[source]

Tries to get the scaling factor of the given Window. Currently works on MacOS only. Useful in figuring out what’s going on with Retina and high-res displays.

Parameters

window (Window) – Handle to window we want to get scaling factor of.

Returns

Scaling factor. E.g., 2 would indicate scaled up twice.

Return type

int

arcade.get_viewport() → Tuple[float, float, float, float][source]

Get the current viewport settings.

Returns

Tuple of floats, with left, right, bottom, top

arcade.get_window() → Optional[pyglet.window.BaseWindow][source]

Return a handle to the current window.

Returns

Handle to the current window.

arcade.pause(seconds: numbers.Number)[source]

Pause for the specified number of seconds. This is a convenience function that just calls time.sleep()

Parameters

seconds (float) – Time interval to pause in seconds.

arcade.quick_run(time_to_pause: numbers.Number)[source]

Only run the application for the specified time in seconds. Useful for unit testing or continuous integration (CI) testing where there is no user interaction.

Parameters

time_to_pause (Number) – Number of seconds to pause before automatically closing.

arcade.run()[source]

Run the main loop. After the window has been set up, and the event hooks are in place, this is usually one of the last commands on the main program.

arcade.schedule(function_pointer: Callable, interval: numbers.Number)[source]

Schedule a function to be automatically called every interval seconds.

Parameters
  • function_pointer (Callable) – Pointer to the function to be called.

  • interval (Number) – Interval to call the function.

arcade.set_background_color(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])[source]

This specifies the background color of the window.

Parameters

color (Color) – List of 3 or 4 bytes in RGB/RGBA format.

arcade.set_viewport(left: float, right: float, bottom: float, top: float)[source]

This sets what coordinates the window will cover.

By default, the lower left coordinate will be (0, 0) and the top y coordinate will be the height of the window in pixels, and the right x coordinate will be the width of the window in pixels.

If a program is making a game where the user scrolls around a larger world, this command can help out.

Note: It is recommended to only set the view port to integer values that line up with the pixels on the screen. Otherwise if making a tiled game the blocks may not line up well, creating rectangle artifacts.

Parameters
  • left (Number) – Left-most (smallest) x value.

  • right (Number) – Right-most (largest) x value.

  • bottom (Number) – Bottom (smallest) y value.

  • top (Number) – Top (largest) y value.

arcade.set_window(window: pyglet.window.BaseWindow)[source]

Set a handle to the current window.

Parameters

window (Window) – Handle to the current window.

arcade.start_render()[source]

Get set up to render. Required to be called before drawing anything to the screen.

arcade.unschedule(function_pointer: Callable)[source]

Unschedule a function being automatically called.

Parameters

function_pointer (Callable) – Pointer to the function to be unscheduled.

Draw Commands

This module contains commands for basic graphics drawing commands. (Drawing primitives.)

Many of these commands are slow, because they load everything to the graphics card each time a shape is drawn. For faster drawing, see the Buffered Draw Commands.

class arcade.Texture(name, image=None)[source]

Bases: object

Class that represents a texture. Usually created by the load_texture or load_textures commands.

Attributes:
name

image

scale

width

Width of the texture image in pixels

height

Height of the texture image in pixels

draw(center_x: float, center_y: float, width: float, height: float, angle: float = 0, alpha: int = 255, transparent: bool = True, repeat_count_x=1, repeat_count_y=1)[source]
Args:

center_x: center_y: width: height: angle: alpha: Currently unused. transparent: Currently unused. repeat_count_x: Currently unused. repeat_count_y: Currently unused.

Returns:

arcade.draw_arc_filled(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], start_angle: float, end_angle: float, tilt_angle: float = 0, num_segments: int = 128)[source]

Draw a filled in arc. Useful for drawing pie-wedges, or Pac-Man.

Parameters
  • center_x (float) – x position that is the center of the arc.

  • center_y (float) – y position that is the center of the arc.

  • width (float) – width of the arc.

  • height (float) – height of the arc.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • start_angle (float) – start angle of the arc in degrees.

  • end_angle (float) – end angle of the arc in degrees.

  • tilt_angle (float) – angle the arc is tilted.

  • num_segments (float) – Number of line segments used to draw arc.

arcade.draw_arc_outline(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], start_angle: float, end_angle: float, border_width: float = 1, tilt_angle: float = 0, num_segments: int = 128)[source]

Draw the outside edge of an arc. Useful for drawing curved lines.

Parameters
  • center_x (float) – x position that is the center of the arc.

  • center_y (float) – y position that is the center of the arc.

  • width (float) – width of the arc.

  • height (float) – height of the arc.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • start_angle (float) – start angle of the arc in degrees.

  • end_angle (float) – end angle of the arc in degrees.

  • border_width (float) – width of line in pixels.

  • tilt_angle (float) – angle the arc is tilted.

  • num_segments (int) – float of triangle segments that make up this circle. Higher is better quality, but slower render time.

arcade.draw_circle_filled(center_x: float, center_y: float, radius: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], num_segments: int = 128)[source]

Draw a filled-in circle.

Parameters
  • center_x (float) – x position that is the center of the circle.

  • center_y (float) – y position that is the center of the circle.

  • radius (float) – width of the circle.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • num_segments (int) – float of triangle segments that make up this circle. Higher is better quality, but slower render time.

arcade.draw_circle_outline(center_x: float, center_y: float, radius: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1, num_segments: int = 128)[source]

Draw the outline of a circle.

Parameters
  • center_x (float) – x position that is the center of the circle.

  • center_y (float) – y position that is the center of the circle.

  • radius (float) – width of the circle.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • border_width (float) – Width of the circle outline in pixels.

  • num_segments (int) – Int of triangle segments that make up this circle. Higher is better quality, but slower render time.

arcade.draw_ellipse_filled(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], tilt_angle: float = 0, num_segments: int = 128)[source]

Draw a filled in ellipse.

Parameters
  • center_x (float) – x position that is the center of the circle.

  • center_y (float) – y position that is the center of the circle.

  • width (float) – width of the ellipse.

  • height (float) – height of the ellipse.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • tilt_angle (float) – Angle in degrees to tilt the ellipse.

  • num_segments (int) – float of triangle segments that make up this circle. Higher is better quality, but slower render time.

arcade.draw_ellipse_outline(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0, num_segments: int = 128)[source]

Draw the outline of an ellipse.

Parameters
  • center_x (float) – x position that is the center of the circle.

  • center_y (float) – y position that is the center of the circle.

  • width (float) – width of the ellipse.

  • height (float) – height of the ellipse.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • border_width (float) – Width of the circle outline in pixels.

  • tilt_angle (float) – Angle in degrees to tilt the ellipse.

  • num_segments (int) – Number of line segments used to make the ellipse

arcade.draw_line(start_x: float, start_y: float, end_x: float, end_y: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], line_width: float = 1)[source]

Draw a line.

Parameters
  • start_x (float) – x position of line starting point.

  • start_y (float) – y position of line starting point.

  • end_x (float) – x position of line ending point.

  • end_y (float) – y position of line ending point.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • line_width (float) – Width of the line in pixels.

arcade.draw_line_strip(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], line_width: float = 1)[source]

Draw a multi-point line.

Parameters
  • point_list (PointList) – List of x, y points that make up this strip

  • color (Color) – Color of line strip

  • line_width (float) – Width of the line

arcade.draw_lines(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], line_width: float = 1)[source]

Draw a set of lines.

Draw a line between each pair of points specified.

Parameters
  • point_list (PointList) – List of points making up the lines. Each point is in a list. So it is a list of lists.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • line_width (float) – Width of the line in pixels.

arcade.draw_lrtb_rectangle_filled(left: float, right: float, top: float, bottom: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])[source]

Draw a rectangle by specifying left, right, top, and bottom edges.

Parameters
  • left (float) – The x coordinate of the left edge of the rectangle.

  • right (float) – The x coordinate of the right edge of the rectangle.

  • top (float) – The y coordinate of the top of the rectangle.

  • bottom (float) – The y coordinate of the rectangle bottom.

  • color (Color) – The color of the rectangle.

Raises AttributeError

Raised if left > right or top < bottom.

arcade.draw_lrtb_rectangle_outline(left: float, right: float, top: float, bottom: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a rectangle by specifying left, right, top, and bottom edges.

Parameters
  • left (float) – The x coordinate of the left edge of the rectangle.

  • right (float) – The x coordinate of the right edge of the rectangle.

  • top (float) – The y coordinate of the top of the rectangle.

  • bottom (float) – The y coordinate of the rectangle bottom.

  • color (Color) – The color of the rectangle.

  • border_width (float) – The width of the border in pixels. Defaults to one.

Raises AttributeError

Raised if left > right or top < bottom.

arcade.draw_parabola_filled(start_x: float, start_y: float, end_x: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], tilt_angle: float = 0)[source]

Draws a filled in parabola.

Parameters
  • start_x (float) – The starting x position of the parabola

  • start_y (float) – The starting y position of the parabola

  • end_x (float) – The ending x position of the parabola

  • height (float) – The height of the parabola

  • color (Color) – The color of the parabola

  • tilt_angle (float) – The angle of the tilt of the parabola

arcade.draw_parabola_outline(start_x: float, start_y: float, end_x: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0)[source]

Draws the outline of a parabola.

Parameters
  • start_x (float) – The starting x position of the parabola

  • start_y (float) – The starting y position of the parabola

  • end_x (float) – The ending x position of the parabola

  • height (float) – The height of the parabola

  • color (Color) – The color of the parabola

  • border_width (float) – The width of the parabola

  • tilt_angle (float) – The angle of the tilt of the parabola

arcade.draw_point(x: float, y: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], size: float)[source]

Draw a point.

Parameters
  • x (float) – x position of point.

  • y (float) – y position of point.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • size (float) – Size of the point in pixels.

arcade.draw_points(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], size: float = 1)[source]

Draw a set of points.

Parameters
  • point_list (PointList) – List of points Each point is in a list. So it is a list of lists.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • size (float) – Size of the point in pixels.

arcade.draw_polygon_filled(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])[source]

Draw a polygon that is filled in.

Args:
point_list

List of points making up the lines. Each point is in a list. So it is a list of lists.

color

color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

Returns:

None

Raises:

None

arcade.draw_polygon_outline(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], line_width: float = 1)[source]

Draw a polygon outline. Also known as a “line loop.”

Parameters
  • point_list (PointList) – List of points making up the lines. Each point is in a list. So it is a list of lists.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • line_width (int) – Width of the line in pixels.

arcade.draw_rectangle_filled(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], tilt_angle: float = 0)[source]

Draw a filled-in rectangle.

Parameters
  • center_x (float) – x coordinate of rectangle center.

  • center_y (float) – y coordinate of rectangle center.

  • width (float) – width of the rectangle.

  • height (float) – height of the rectangle.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • tilt_angle (float) – rotation of the rectangle. Defaults to zero.

arcade.draw_rectangle_outline(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0)[source]

Draw a rectangle outline.

Parameters
  • center_x (float) – x coordinate of top left rectangle point.

  • center_y (float) – y coordinate of top left rectangle point.

  • width (float) – width of the rectangle.

  • height (float) – height of the rectangle.

  • color (Color) – color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

  • border_width (float) – width of the lines, in pixels.

  • tilt_angle (float) – rotation of the rectangle. Defaults to zero.

arcade.draw_texture_rectangle(center_x: float, center_y: float, width: float, height: float, texture: arcade.Texture, angle: float = 0, alpha: int = 255, repeat_count_x: int = 1, repeat_count_y: int = 1)[source]

Draw a textured rectangle on-screen.

Parameters
  • center_x (float) – x coordinate of rectangle center.

  • center_y (float) – y coordinate of rectangle center.

  • width (float) – width of the rectangle.

  • height (float) – height of the rectangle.

  • texture (int) – identifier of texture returned from load_texture() call

  • angle (float) – rotation of the rectangle. Defaults to zero.

  • alpha (float) – Transparency of image. 0 is fully transparent, 255 (default) is visible

  • repeat_count_x (int) – Unused for now

  • repeat_count_y (int) – Unused for now

arcade.draw_triangle_filled(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])[source]

Draw a filled in triangle.

Parameters
  • x1 (float) – x value of first coordinate.

  • y1 (float) – y value of first coordinate.

  • x2 (float) – x value of second coordinate.

  • y2 (float) – y value of second coordinate.

  • x3 (float) – x value of third coordinate.

  • y3 (float) – y value of third coordinate.

  • color (Color) – Color of triangle.

arcade.draw_triangle_outline(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a the outline of a triangle.

Parameters
  • x1 (float) – x value of first coordinate.

  • y1 (float) – y value of first coordinate.

  • x2 (float) – x value of second coordinate.

  • y2 (float) – y value of second coordinate.

  • x3 (float) – x value of third coordinate.

  • y3 (float) – y value of third coordinate.

  • color (Color) – Color of triangle.

  • border_width (float) – Width of the border in pixels. Defaults to 1.

arcade.draw_xywh_rectangle_filled(bottom_left_x: float, bottom_left_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])[source]

Draw a filled rectangle extending from bottom left to top right

Parameters
  • bottom_left_x (float) – The x coordinate of the left edge of the rectangle.

  • bottom_left_y (float) – The y coordinate of the bottom of the rectangle.

  • width (float) – The width of the rectangle.

  • height (float) – The height of the rectangle.

  • color (Color) – The color of the rectangle.

arcade.draw_xywh_rectangle_outline(bottom_left_x: float, bottom_left_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a rectangle extending from bottom left to top right

Parameters
  • bottom_left_x (float) – The x coordinate of the left edge of the rectangle.

  • bottom_left_y (float) – The y coordinate of the bottom of the rectangle.

  • width (float) – The width of the rectangle.

  • height (float) – The height of the rectangle.

  • color (Color) – The color of the rectangle.

  • border_width (float) – The width of the border in pixels. Defaults to one.

arcade.draw_xywh_rectangle_textured(bottom_left_x: float, bottom_left_y: float, width: float, height: float, texture: arcade.Texture, angle: float = 0, alpha: int = 255, repeat_count_x: int = 1, repeat_count_y: int = 1)[source]

Draw a texture extending from bottom left to top right.

Parameters
  • bottom_left_x (float) – The x coordinate of the left edge of the rectangle.

  • bottom_left_y (float) – The y coordinate of the bottom of the rectangle.

  • width (float) – The width of the rectangle.

  • height (float) – The height of the rectangle.

  • texture (int) – identifier of texture returned from load_texture() call

  • angle (float) – rotation of the rectangle. Defaults to zero.

  • alpha (int) – Transparency of image. 0 is fully transparent, 255 (default) is visible

  • repeat_count_x (int) – Unused for now

  • repeat_count_y (int) – Unused for now

arcade.get_four_byte_color(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]) → Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]][source]

Given a RGB list, it will return RGBA. Given a RGBA list, it will return the same RGBA.

Parameters

color (Color) – Three or four byte tuple

Returns

return: Four byte RGBA tuple

arcade.get_four_float_color(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]) → Tuple[float, float, float, float][source]

Given a 3 or 4 RGB/RGBA color where each color goes 0-255, this returns a RGBA tuple where each item is a scaled float from 0 to 1.

Parameters

color (Color) – Three or four byte tuple

Returns

Four floats as a RGBA tuple

arcade.get_image(x: int = 0, y: int = 0, width: int = None, height: int = None)[source]

Get an image from the screen.

Parameters
  • x (int) – Start (left) x location

  • y (int) – Start (top) y location

  • width (int) – Width of image. Leave blank for grabbing the ‘rest’ of the image

  • height (int) – Height of image. Leave blank for grabbing the ‘rest’ of the image

You can save the image like:

image = get_image()
image.save('screenshot.png', 'PNG')
arcade.get_pixel(x: int, y: int)[source]

Given an x, y, will return RGB color value of that point.

Parameters
  • x (int) – x location

  • y (int) – y location

Returns

Color

arcade.load_texture(file_name: str, x: float = 0, y: float = 0, width: float = 0, height: float = 0, mirrored: bool = False, flipped: bool = False, scale: float = 1) → arcade.Texture[source]

Load image from disk and create a texture.

Note, if the code is to load only part of the image, the given x, y coordinates will start with the origin (0, 0) in the upper left of the image. When drawing, Arcade uses (0, 0) in the lower left corner when drawing. Be careful about this reversal.

For a longer explanation of why computers sometimes start in the upper left, see: http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5

Parameters
  • file_name (str) – Name of the file to that holds the texture.

  • x (float) – X position of the crop area of the texture.

  • y (float) – Y position of the crop area of the texture.

  • width (float) – Width of the crop area of the texture.

  • height (float) – Height of the crop area of the texture.

  • mirrored (bool) – True if we mirror the image across the y axis

  • flipped (bool) – True if we flip the image across the x axis

  • scale (float) – Scale factor to apply on the new texture.

Returns

The new texture.

Raises

None

arcade.load_textures(file_name: str, image_location_list: Union[Tuple[Union[Tuple[float, float, float, float], List[float]], ...], List[Union[Tuple[float, float, float, float], List[float]]]], mirrored: bool = False, flipped: bool = False, scale: float = 1) → List[arcade.Texture][source]

Load a set of textures off of a single image file.

Note, if the code is to load only part of the image, the given x, y coordinates will start with the origin (0, 0) in the upper left of the image. When drawing, Arcade uses (0, 0) in the lower left corner when drawing. Be careful about this reversal.

For a longer explanation of why computers sometimes start in the upper left, see: http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5

Parameters
  • file_name (str) – Name of the file.

  • image_location_list (RectList) – List of image sub-locations. Each rectangle should be a list of four floats. [x, y, width, height].

  • mirrored (bool) – If set to true, the image is mirrored left to right.

  • flipped (bool) – If set to true, the image is flipped upside down.

  • scale (float) – Scale factor to apply on each new texture.

Returns

List of textures loaded.

Raises

ValueError

arcade.make_circle_texture(diameter: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]) → arcade.Texture[source]

Return a Texture of a circle with given diameter and color

Parameters
  • diameter (int) – Diameter of the circle and dimensions of the square Texture returned

  • color (Color) – Color of the circle

Returns

A Texture object

Raises

None

arcade.make_soft_circle_texture(diameter: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], center_alpha: int = 255, outer_alpha: int = 0) → arcade.Texture[source]

Return a Texture of a circle with given diameter, color, and alpha values at its center and edges

Args:
diameter (int)

Diameter of the circle and dimensions of the square Texture returned

color (Color)

Color of the circle

center_alpha (int)

alpha value of circle at its center

outer_alpha (int)

alpha value of circle at its edge

Returns:

A Texture object

Raises:

None

arcade.make_soft_square_texture(size: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], center_alpha: int = 255, outer_alpha: int = 0) → arcade.Texture[source]

Return a Texture of a circle with given diameter and color, fading out at the edges.

Args:
diameter (int)

Diameter of the circle and dimensions of the square Texture returned

color (Color)

Color of the circle

Returns:

The new texture.

Raises:

None

arcade.make_transparent_color(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], transparency: float)[source]

Given a RGB color, along with an alpha, returns a RGBA color tuple.

Parameters
  • color (Color) – Three or four byte RGBA color

  • transparency (float) – Transparency

arcade.rotate_point(x: float, y: float, cx: float, cy: float, angle: float) → Tuple[float, float][source]

Rotate a point around a center.

Parameters
  • x – x value of the point you want to rotate

  • y – y value of the point you want to rotate

  • cx – x value of the center point you want to rotate around

  • cy – y value of the center point you want to rotate around

  • angle – Angle, in degrees, to rotate

Returns

Return rotated (x, y) pair

Return type

(float, float)

arcade.trim_image(image: <module 'PIL.Image' from 'c:\\program files (x86)\\python37-32\\lib\\site-packages\\PIL\\Image.py'>) → <module 'PIL.Image' from 'c:\\program files (x86)\\python37-32\\lib\\site-packages\\PIL\\Image.py'>[source]

Returns an image with extra whitespace cropped out.

Buffered Draw Commands

Drawing commands that use vertex buffer objects (VBOs).

This module contains commands for basic graphics drawing commands, but uses Vertex Buffer Objects. This keeps the vertices loaded on the graphics card for much faster render times.

class arcade.Shape[source]

Bases: object

draw()[source]
class arcade.ShapeElementList[source]

Bases: typing.Generic

A program can put multiple drawing primitives in a ShapeElementList, and then move and draw them as one. Do this when you want to create a more complex object out of simpler primitives. This also speeds rendering as all objects are drawn in one operation.

property angle

Get the angle of the ShapeElementList in degrees.

append(item: TShape)[source]

Add a new shape to the list.

property center_x

Get the center x coordinate of the ShapeElementList.

property center_y

Get the center y coordinate of the ShapeElementList.

draw()[source]

Draw everything in the list.

move(change_x: float, change_y: float)[source]

Move all the shapes ion the list :param change_x: Amount to move on the x axis :param change_y: Amount to move on the y axis

remove(item: TShape)[source]

Remove a specific shape from the list.

class arcade.VertexBuffer(vbo_vertex_id: ctypes.c_ulong, size: float, draw_mode: int, vbo_color_id: ctypes.c_ulong = None)[source]

Bases: object

This class represents a vertex buffer object for internal library use. Clients of the library probably don’t need to use this.

Attributes:
vbo_id

ID of the vertex buffer as assigned by OpenGL

size

width

height

color

arcade.create_ellipse(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0, num_segments: int = 32, filled=True) → arcade.Shape[source]

This creates an ellipse vertex buffer object (VBO). It can later be drawn with render_ellipse_filled. This method of drawing an ellipse is much faster than calling draw_ellipse_filled each frame.

Note: This can’t be unit tested on Appveyor because its support for OpenGL is poor.

arcade.create_ellipse_filled(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], tilt_angle: float = 0, num_segments: int = 128) → arcade.Shape[source]

Create a filled ellipse. Or circle if you use the same width and height.

arcade.create_ellipse_filled_with_colors(center_x: float, center_y: float, width: float, height: float, outside_color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], inside_color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], tilt_angle: float = 0, num_segments: int = 32) → arcade.Shape[source]

Draw an ellipse, and specify inside/outside color. Used for doing gradients.

Parameters
  • center_x (float) –

  • center_y (float) –

  • width (float) –

  • height (float) –

  • outside_color (Color) –

  • inside_color (float) –

  • tilt_angle (float) –

  • num_segments (int) –

Returns Shape

arcade.create_ellipse_outline(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0, num_segments: int = 128) → arcade.Shape[source]

Create an outline of an ellipse.

arcade.create_line(start_x: float, start_y: float, end_x: float, end_y: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], line_width: float = 1) → arcade.Shape[source]

Create a line to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame.

Parameters
Returns Shape

arcade.create_line_generic(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], shape_mode: int, line_width: float = 1) → arcade.Shape[source]

This function is used by create_line_strip and create_line_loop, just changing the OpenGL type for the line drawing.

arcade.create_line_generic_with_colors(point_list: Sequence[Union[Tuple[float, float], List[float]]], color_list: Iterable[Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]], shape_mode: int, line_width: float = 1) → arcade.Shape[source]

This function is used by create_line_strip and create_line_loop, just changing the OpenGL type for the line drawing.

Parameters
  • point_list (PointList) –

  • color_list (Iterable[Color]) –

  • shape_mode (float) –

  • line_width (float) –

Returns Shape

arcade.create_line_loop(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], line_width: float = 1)[source]

Create a multi-point line loop to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame.

Parameters
  • point_list (PointList) –

  • color (Color) –

  • line_width (float) –

Returns Shape

arcade.create_line_strip(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], line_width: float = 1)[source]

Create a multi-point line to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame.

Parameters
  • point_list (PointList) –

  • color (Color) –

  • line_width (PointList) –

Returns Shape

arcade.create_lines(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], line_width: float = 1)[source]

Create a multi-point line loop to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame.

Parameters
  • point_list (PointList) –

  • color (Color) –

  • line_width (float) –

Returns Shape

arcade.create_lines_with_colors(point_list: Sequence[Union[Tuple[float, float], List[float]]], color_list: Sequence[Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]], line_width: float = 1)[source]
arcade.create_polygon(point_list: Sequence[Union[Tuple[float, float], List[float]]], color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])[source]

Draw a convex polygon. This will NOT draw a concave polygon. Because of this, you might not want to use this function.

Parameters
  • point_list (PointList) –

  • color

Returns Shape

arcade.create_rectangle(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0, filled=True) → arcade.Shape[source]

This function creates a rectangle using a vertex buffer object. Creating the rectangle, and then later drawing it with render_rectangle is faster than calling draw_rectangle.

Args:

center_x: center_y: width: height: color: border_width: tilt_angle: filled:

Returns:

arcade.create_rectangle_filled(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], tilt_angle: float = 0) → arcade.Shape[source]

Create a filled rectangle.

Parameters
Returns Shape

arcade.create_rectangle_filled_with_colors(point_list, color_list) → arcade.Shape[source]

This function creates one rectangle/quad using a vertex buffer object. Creating the rectangles, and then later drawing it with render is faster than calling draw_rectangle.

arcade.create_rectangle_outline(center_x: float, center_y: float, width: float, height: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0) → arcade.Shape[source]

Create a rectangle outline.

Args:

center_x: center_y: width: height: color: border_width: tilt_angle:

Returns:

arcade.create_rectangles_filled_with_colors(point_list, color_list) → arcade.Shape[source]

This function creates multiple rectangle/quads using a vertex buffer object. Creating the rectangles, and then later drawing it with render is faster than calling draw_rectangle.

arcade.create_triangles_filled_with_colors(point_list, color_list) → arcade.Shape[source]

This function creates multiple rectangle/quads using a vertex buffer object. Creating the rectangles, and then later drawing it with render is faster than calling draw_rectangle.

arcade.get_rectangle_points(center_x: float, center_y: float, width: float, height: float, tilt_angle: float = 0) → Sequence[Union[Tuple[float, float], List[float]]][source]

Utility function that will return all four coordinate points of a rectangle given the x, y center, width, height, and rotation.

Args:

center_x: center_y: width: height: tilt_angle:

Returns:

Text Drawing

class arcade.CreateText(text: str, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], font_size: float = 12, width: int = 20, align='left', font_name=('Calibri', 'Arial'), bold: bool = False, italic: bool = False, anchor_x='left', anchor_y='baseline', rotation=0)[source]

Bases: object

Class used for managing text

class arcade.Text[source]

Bases: object

Class used for managing text.

arcade.create_text(text: str, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], font_size: float = 12, width: int = 0, align='left', font_name=('Calibri', 'Arial'), bold: bool = False, italic: bool = False, anchor_x: str = 'left', anchor_y: str = 'baseline', rotation=0)[source]

Deprecated. Two step text drawing for backwards compatibility.

arcade.draw_text(text: str, start_x: float, start_y: float, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], font_size: float = 12, width: int = 0, align: str = 'left', font_name: Union[str, Tuple[str, ...]] = ('calibri', 'arial'), bold: bool = False, italic: bool = False, anchor_x: str = 'left', anchor_y: str = 'baseline', rotation: float = 0)[source]
Parameters
  • text (str) – Text to draw

  • start_x (float) –

  • start_y (float) –

  • color (Color) – Color of the text

  • font_size (float) – Size of the text

  • width (float) –

  • align (str) –

  • Tuple[str, ..]] font_name (Union[str,) –

  • bold (bool) –

  • italic (bool) –

  • anchor_x (str) –

  • anchor_y (str) –

  • rotation (float) –

arcade.render_text(text: arcade.CreateText, start_x: float, start_y: float)[source]

Deprecated. Two step text drawing for backwards compatibility.

Window Class

The main window class that all object-oriented applications should derive from.

exception arcade.NoOpenGLException[source]

Bases: Exception

Exception when we can’t get an OpenGL 3.3+ context

class arcade.View[source]

Bases: object

TODO:Thoughts: - is there a need for a close()/on_close() method?

on_draw()[source]

Called when this view should draw

on_key_press(symbol: int, modifiers: int)[source]

Override this function to add key press functionality.

Parameters
  • symbol (int) – Key that was hit

  • modifiers (int) – If it was shift/ctrl/alt

on_key_release(_symbol: int, _modifiers: int)[source]

Override this function to add key release functionality.

Parameters
  • _symbol (int) – Key that was hit

  • _modifiers (int) – If it was shift/ctrl/alt

on_mouse_drag(x: float, y: float, dx: float, dy: float, _buttons: int, _modifiers: int)[source]

Override this function to add mouse button functionality.

Parameters
  • x (float) – x position of mouse

  • y (float) – y position of mouse

  • dx (float) – Change in x since the last time this method was called

  • dy (float) – Change in y since the last time this method was called

  • _buttons (int) – Which button is pressed

  • _modifiers (int) – Ctrl, shift, etc.

on_mouse_motion(x: float, y: float, dx: float, dy: float)[source]

Override this function to add mouse functionality.

Parameters
  • x (float) – x position of mouse

  • y (float) – y position of mouse

  • dx (float) – Change in x since the last time this method was called

  • dy (float) – Change in y since the last time this method was called

on_mouse_press(x: float, y: float, button: int, modifiers: int)[source]

Override this function to add mouse button functionality.

Parameters
  • x (float) – x position of the mouse

  • y (float) – y position of the mouse

  • button (int) – What button was hit. One of: arcade.MOUSE_BUTTON_LEFT, arcade.MOUSE_BUTTON_RIGHT, arcade.MOUSE_BUTTON_MIDDLE

  • modifiers (int) – Shift/click, ctrl/click, etc.

on_mouse_release(x: float, y: float, button: int, modifiers: int)[source]

Override this function to add mouse button functionality.

Parameters
on_mouse_scroll(x: int, y: int, scroll_x: int, scroll_y: int)[source]

User moves the scroll wheel.

Parameters
  • x (int) –

  • y (int) –

  • scroll_x (int) –

  • scroll_y (int) –

on_show()[source]

Called when this view is shown

on_update(delta_time: float)[source]

To be overridden

update(delta_time: float)[source]

To be overridden

class arcade.Window(width: int = 800, height: int = 600, title: str = 'Arcade Window', fullscreen: bool = False, resizable: bool = False, update_rate: Optional[float] = 0.016666666666666666, antialiasing: bool = True)[source]

Bases: pyglet.window.Window

The Window class forms the basis of most advanced games that use Arcade. It represents a window on the screen, and manages events.

activate()[source]

Attempt to restore keyboard focus to the window.

Depending on the window manager or operating system, this may not be successful. For example, on Windows XP an application is not allowed to “steal” focus from another application. Instead, the window’s taskbar icon will flash, indicating it requires attention.

dispatch_events()[source]

Poll the operating system event queue for new events and call attached event handlers.

This method is provided for legacy applications targeting pyglet 1.0, and advanced applications that must integrate their event loop into another framework.

Typical applications should use pyglet.app.run.

flip()[source]

Swap the OpenGL front and back buffers.

Call this method on a double-buffered window to update the visible display with the back buffer. The contents of the back buffer is undefined after this operation.

Windows are double-buffered by default. This method is called automatically by EventLoop after the on_draw() event.

get_location() → Tuple[int, int][source]

Return the X/Y coordinates of the window

Returns

x, y of window location

get_size() → Tuple[int, int][source]

Get the size of the window.

Returns

(width, height)

get_system_mouse_cursor(name)[source]

Obtain a system mouse cursor.

Use set_mouse_cursor to make the cursor returned by this method active. The names accepted by this method are the CURSOR_* constants defined on this class.

Parameters
namestr

Name describing the mouse cursor to return. For example, CURSOR_WAIT, CURSOR_HELP, etc.

Return type

MouseCursor

Returns

A mouse cursor which can be used with set_mouse_cursor.

get_viewport() → Tuple[float, float, float, float][source]

Get the viewport. (What coordinates we can see.)

maximize()[source]

Maximize the window.

The behaviour of this method is somewhat dependent on the user’s display setup. On a multi-monitor system, the window may maximize to either a single screen or the entire virtual desktop.

minimize()[source]

Minimize the window.

on_draw()[source]

Override this function to add your custom drawing code.

on_key_press(symbol: int, modifiers: int)[source]

Override this function to add key press functionality.

Parameters
  • symbol (int) – Key that was hit

  • modifiers (int) – If it was shift/ctrl/alt

on_key_release(symbol: int, modifiers: int)[source]

Override this function to add key release functionality.

Parameters
  • symbol (int) – Key that was hit

  • modifiers (int) – If it was shift/ctrl/alt

on_mouse_drag(x: float, y: float, dx: float, dy: float, buttons: int, modifiers: int)[source]

Override this function to add mouse button functionality.

Parameters
  • x (float) – x position of mouse

  • y (float) – y position of mouse

  • dx (float) – Change in x since the last time this method was called

  • dy (float) – Change in y since the last time this method was called

  • buttons (int) – Which button is pressed

  • modifiers (int) – Ctrl, shift, etc.

on_mouse_motion(x: float, y: float, dx: float, dy: float)[source]

Override this function to add mouse functionality.

Parameters
  • x (float) – x position of mouse

  • y (float) – y position of mouse

  • dx (float) – Change in x since the last time this method was called

  • dy (float) – Change in y since the last time this method was called

on_mouse_press(x: float, y: float, button: int, modifiers: int)[source]

Override this function to add mouse button functionality.

Parameters
  • x (float) – x position of the mouse

  • y (float) – y position of the mouse

  • button (int) – What button was hit. One of: arcade.MOUSE_BUTTON_LEFT, arcade.MOUSE_BUTTON_RIGHT, arcade.MOUSE_BUTTON_MIDDLE

  • modifiers (int) – Shift/click, ctrl/click, etc.

on_mouse_release(x: float, y: float, button: int, modifiers: int)[source]

Override this function to add mouse button functionality.

Parameters
on_mouse_scroll(x: int, y: int, scroll_x: int, scroll_y: int)[source]

User moves the scroll wheel.

Parameters
  • x (int) –

  • y (int) –

  • scroll_x (int) –

  • scroll_y (int) –

on_resize(width: float, height: float)[source]

Override this function to add custom code to be called any time the window is resized.

Parameters
  • width (float) – New width

  • height (float) – New height

on_update(delta_time: float)[source]

Move everything. Perform collision checks. Do all the game logic here.

Parameters

delta_time (float) – Time interval since the last time the function was called.

set_caption(caption)[source]

Set the window’s caption.

The caption appears in the titlebar of the window, if it has one, and in the taskbar on Windows and many X11 window managers.

Parameters
captionstr or unicode

The caption to set.

set_exclusive_keyboard(exclusive=True)[source]

Prevent the user from switching away from this window using keyboard accelerators.

When enabled, this feature disables certain operating-system specific key combinations such as Alt+Tab (Command+Tab on OS X). This can be useful in certain kiosk applications, it should be avoided in general applications or games.

Parameters
exclusivebool

If True, exclusive keyboard is enabled, otherwise it is disabled.

set_exclusive_mouse(exclusive=True)[source]

Hide the mouse cursor and direct all mouse events to this window.

When enabled, this feature prevents the mouse leaving the window. It is useful for certain styles of games that require complete control of the mouse. The position of the mouse as reported in subsequent events is meaningless when exclusive mouse is enabled; you should only use the relative motion parameters dx and dy.

Parameters
exclusivebool

If True, exclusive mouse is enabled, otherwise it is disabled.

set_location(x, y)[source]

Set the position of the window.

Parameters
xint

Distance of the left edge of the window from the left edge of the virtual desktop, in pixels.

yint

Distance of the top edge of the window from the top edge of the virtual desktop, in pixels.

set_max_size(width: float, height: float)[source]

Wrap the Pyglet window call to set maximum size

Parameters
  • width (float) – width in pixels.

  • height (float) – height in pixels.

Raises ValueError

set_maximum_size(width, height)[source]

Set the maximum size of the window.

Once set, the user will not be able to resize the window larger than the given dimensions. There is no way to remove the maximum size constraint on a window (but you could set it to a large value).

The behaviour is undefined if the maximum size is set smaller than the current size of the window.

The window size does not include the border or title bar.

Parameters
widthint

Maximum width of the window, in pixels.

heightint

Maximum height of the window, in pixels.

set_min_size(width: float, height: float)[source]

Wrap the Pyglet window call to set minimum size

Parameters
  • width (float) – width in pixels.

  • height (float) – height in pixels.

set_minimum_size(width, height)[source]

Set the minimum size of the window.

Once set, the user will not be able to resize the window smaller than the given dimensions. There is no way to remove the minimum size constraint on a window (but you could set it to 0,0).

The behaviour is undefined if the minimum size is set larger than the current size of the window.

The window size does not include the border or title bar.

Parameters
widthint

Minimum width of the window, in pixels.

heightint

Minimum height of the window, in pixels.

set_mouse_platform_visible(platform_visible=None)[source]

Set the platform-drawn mouse cursor visibility. This is called automatically after changing the mouse cursor or exclusive mode.

Applications should not normally need to call this method, see set_mouse_visible instead.

Parameters
platform_visiblebool or None

If None, sets platform visibility to the required visibility for the current exclusive mode and cursor type. Otherwise, a bool value will override and force a visibility.

set_mouse_visible(visible: bool = True)[source]

If true, user can see the mouse cursor while it is over the window. Set false, the mouse is not visible. Default is true.

Parameters

visible (bool) –

set_size(width: float, height: float)[source]

Ignore the resizable flag and set the size

Parameters
set_update_rate(rate: float)[source]

Set how often the screen should be updated. For example, self.set_update_rate(1 / 60) will set the update rate to 60 fps

Parameters

rate (float) – Update frequency in seconds

set_viewport(left: float, right: float, bottom: float, top: float)[source]

Set the viewport. (What coordinates we can see. Used to scale and/or scroll the screen.)

Parameters
  • left (Number) –

  • right (Number) –

  • bottom (Number) –

  • top (Number) –

set_visible(visible=True)[source]

Set if the window is visible or not. Normally, a program’s window is visible.

Parameters

visible (bool) –

set_vsync(vsync)[source]

Enable or disable vertical sync control.

When enabled, this option ensures flips from the back to the front buffer are performed only during the vertical retrace period of the primary display. This can prevent “tearing” or flickering when the buffer is updated in the middle of a video scan.

Note that LCD monitors have an analogous time in which they are not reading from the video buffer; while it does not correspond to a vertical retrace it has the same effect.

Also note that with multi-monitor systems the secondary monitor cannot be synchronised to, so tearing and flicker cannot be avoided when the window is positioned outside of the primary display.

Parameters
vsyncbool

If True, vsync is enabled, otherwise it is disabled.

show_view(new_view: arcade.View)[source]
switch_to()[source]

Make this window the current OpenGL rendering context.

Only one OpenGL context can be active at a time. This method sets the current window’s context to be current. You should use this method in preference to pyglet.gl.Context.set_current, as it may perform additional initialisation functions.

test(frames: int = 10)[source]

Used by unit test cases. Runs the event loop a few times and stops.

Parameters

frames (int) –

update(delta_time: float)[source]

Move everything. For better consistency in naming, use on_update instead.

Parameters

delta_time (float) – Time interval since the last time the function was called in seconds.

arcade.open_window(width: int, height: int, window_title: str, resizable: bool = False, antialiasing: bool = True) → arcade.Window[source]

This function opens a window. For ease-of-use we assume there will only be one window, and the programmer does not need to keep a handle to the window. This isn’t the best architecture, because the window handle is stored in a global, but it makes things easier for programmers if they don’t have to track a window pointer.

Parameters
  • width (Number) – Width of the window.

  • height (Number) – Height of the window.

  • window_title (str) – Title of the window.

  • resizable (bool) – Whether the window can be user-resizable.

  • antialiasing (bool) – Smooth the graphics?

Returns

Handle to window

Rtype arcade.Window

Game Controllers

arcade.joysticks.get_game_controllers()[source]

Get a list of all the game controllers

Returns

List of game controllers

arcade.joysticks.get_joysticks()[source]

Get a list of all the game controllers

This is an alias of get_game_controllers, which is better worded.

Returns

List of game controllers

Geometry Commands

Functions for calculating geometry.

arcade.are_polygons_intersecting(poly_a: Sequence[Union[Tuple[float, float], List[float]]], poly_b: Sequence[Union[Tuple[float, float], List[float]]]) → bool[source]

Return True if two polygons intersect.

Parameters
  • poly_a (PointList) – List of points that define the first polygon.

  • poly_b (PointList) – List of points that define the second polygon.

Returns

True or false depending if polygons intersect

Rtype bool

arcade.check_for_collision(sprite1: arcade.Sprite, sprite2: arcade.Sprite) → bool[source]

Check for a collision between two sprites.

Parameters
  • sprite1 – First sprite

  • sprite2 – Second sprite

Returns

True or False depending if the sprites intersect.

arcade.check_for_collision_with_list(sprite: arcade.Sprite, sprite_list: arcade.SpriteList) → List[arcade.Sprite][source]

Check for a collision between a sprite, and a list of sprites.

Parameters
  • sprite (Sprite) – Sprite to check

  • sprite_list (SpriteList) – SpriteList to check against

Returns

List of sprites colliding, or an empty list.

arcade.get_sprites_at_point(point: Union[Tuple[float, float], List[float]], sprite_list: arcade.SpriteList) → List[arcade.Sprite][source]

Get a list of sprites at a particular point

Parameters
  • point (Point) – Point to check

  • sprite_list (SpriteList) – SpriteList to check against

Returns

List of sprites colliding, or an empty list.

arcade.is_point_in_polygon(x, y, polygon_point_list)[source]

Use ray-tracing to see if point is inside a polygon

Args:

x: y: polygon_point_list:

Returns: bool

Sprite Commands

This module manages all of the code around Sprites.

For information on Spatial Hash Maps, see: https://www.gamedev.net/articles/programming/general-and-gameplay-programming/spatial-hashing-r2697/

class arcade.AnimatedTimeBasedSprite(filename: str = None, scale: float = 1, image_x: float = 0, image_y: float = 0, image_width: float = 0, image_height: float = 0, center_x: float = 0, center_y: float = 0, _repeat_count_x=1, _repeat_count_y=1)[source]

Bases: arcade.Sprite

Sprite for platformer games that supports animations.

update_animation(delta_time: float = 0.016666666666666666)[source]

Logic for selecting the proper texture to use.

class arcade.AnimatedTimeSprite(scale: float = 1, image_x: float = 0, image_y: float = 0, center_x: float = 0, center_y: float = 0)[source]

Bases: arcade.Sprite

Sprite for platformer games that supports animations.

update_animation(delta_time: float = 0.016666666666666666)[source]

Logic for selecting the proper texture to use.

class arcade.AnimatedWalkingSprite(scale: float = 1, image_x: float = 0, image_y: float = 0, center_x: float = 0, center_y: float = 0)[source]

Bases: arcade.Sprite

Sprite for platformer games that supports animations.

update_animation(delta_time: float = 0.016666666666666666)[source]

Logic for selecting the proper texture to use.

class arcade.AnimationKeyframe(tile_id: int, duration: int, image: <module 'PIL.Image' from 'c:\program files (x86)\python37-32\lib\site-packages\PIL\Image.py'>)[source]

Bases: object

class arcade.Sprite(filename: str = None, scale: float = 1, image_x: float = 0, image_y: float = 0, image_width: float = 0, image_height: float = 0, center_x: float = 0, center_y: float = 0, repeat_count_x: int = 1, repeat_count_y: int = 1)[source]

Bases: object

Class that represents a ‘sprite’ on-screen.

Attributes:
alpha

Transparency of sprite. 0 is invisible, 255 is opaque.

angle

Rotation angle in degrees.

radians

Rotation angle in radians.

bottom

Set/query the sprite location by using the bottom coordinate. This will be the ‘y’ of the bottom of the sprite.

boundary_left

Used in movement. Left boundary of moving sprite.

boundary_right

Used in movement. Right boundary of moving sprite.

boundary_top

Used in movement. Top boundary of moving sprite.

boundary_bottom

Used in movement. Bottom boundary of moving sprite.

center_x

X location of the center of the sprite

center_y

Y location of the center of the sprite

change_x

Movement vector, in the x direction.

change_y

Movement vector, in the y direction.

change_angle

Change in rotation.

color

Color tint the sprite

collision_radius

Used as a fast-check to see if this item is close enough to another item. If this check works, we do a slower more accurate check.

cur_texture_index

Index of current texture being used.

guid

Unique identifier for the sprite. Useful when debugging.

height

Height of the sprite.

force

Force being applied to the sprite. Useful when used with Pymunk for physics.

left

Set/query the sprite location by using the left coordinate. This will be the ‘x’ of the left of the sprite.

points

Points, in relation to the center of the sprite, that are used for collision detection. Arcade defaults to creating points for a rectangle that encompass the image. If you are creating a ramp or making better hit-boxes, you can custom-set these.

position

A list with the (x, y) of where the sprite is.

repeat_count_x

Unused

repeat_count_y

Unused

right

Set/query the sprite location by using the right coordinate. This will be the ‘y=x’ of the right of the sprite.

sprite_lists

List of all the sprite lists this sprite is part of.

texture

Texture class with the current texture.

textures

List of textures associated with this sprite.

top

Set/query the sprite location by using the top coordinate. This will be the ‘y’ of the top of the sprite.

scale

Scale the image up or down. Scale of 1.0 is original size, 0.5 is 1/2 height and width.

velocity

Change in x, y expressed as a list. (0, 0) would be not moving.

width

Width of the sprite

It is common to over-ride the update method and provide mechanics on movement or other sprite updates.

add_spatial_hashes()[source]
property alpha

Return the alpha associated with the sprite.

property angle

Get the angle of the sprite’s rotation.

append_texture(texture: arcade.Texture)[source]

Appends a new texture to the list of textures that can be applied to this sprite.

Parameters

texture (Texture) – Texture to add ot the list of available textures

property bottom

Return the y coordinate of the bottom of the sprite.

property center_x

Get the center x coordinate of the sprite.

property center_y

Get the center y coordinate of the sprite.

property change_x

Get the velocity in the x plane of the sprite.

property change_y

Get the velocity in the y plane of the sprite.

clear_spatial_hashes()[source]

Search the sprite lists this sprite is a part of, and remove it from any spatial hashes it is a part of.

collides_with_list(sprite_list: SpriteList) → list[source]

Check if current sprite is overlapping with any other sprite in a list

Args:

self: current Sprite sprite_list: SpriteList to check against

Returns:

SpriteList of all overlapping Sprites from the original SpriteList

collides_with_point(point: Union[Tuple[float, float], List[float]]) → bool[source]

Check if point is within the current sprite.

Args:

self: Current sprite point: Point to check.

Returns:

True if the point is contained within the sprite’s boundary.

collides_with_sprite(other: arcade.Sprite) → bool[source]

Will check if a sprite is overlapping (colliding) another Sprite.

Args:

self: Current Sprite. other: The other sprite to check against.

Returns:

True or False, whether or not they are overlapping.

property collision_radius

Get the collision radius.

Note

Final collision checking is done via geometry that was set in get_points/set_points. These points are used in the check_for_collision function. This collision_radius variable is used as a “pre-check.” We do a super-fast check with collision_radius and see if the sprites are close. If they are, then we look at the geometry and figure if they really are colliding.

property color

Return the RGB color associated with the sprite.

draw()[source]

Draw the sprite.

forward(speed: float = 1.0)[source]

Set a Sprite’s position to speed by its angle :param speed: speed factor

get_points() → Tuple[Tuple[float, float], ...][source]

Get the corner points for the rect that makes up the sprite.

property height

Get the height in pixels of the sprite.

kill()[source]

Alias of remove_from_sprite_lists

property left

Left-most coordinate.

property points

Get the corner points for the rect that makes up the sprite.

property position

Get the center x coordinate of the sprite.

Returns:

(width, height)

property radians

Converts the degrees representation of self.angle into radians. :return: float

register_sprite_list(new_list)[source]

Register this sprite as belonging to a list. We will automatically remove ourselves from the the list when kill() is called.

remove_from_sprite_lists()[source]

Remove the sprite from all sprite lists.

rescale_relative_to_point(point: Union[Tuple[float, float], List[float]], factor: float) → None[source]

Rescale the sprite relative to a different point than its center.

reverse(speed: float = 1.0)[source]
property right

Return the x coordinate of the right-side of the sprite.

property scale

Get the scale of the sprite.

set_points(points: Sequence[Sequence[float]])[source]

Set a sprite’s position

set_position(center_x: float, center_y: float)[source]

Set a sprite’s position

Parameters
  • center_x (float) – New x position of sprite

  • center_y (float) – New y position of sprite

set_texture(texture_no: int)[source]

Sets texture by texture id. Should be renamed because it takes a number rather than a texture, but keeping this for backwards compatibility.

stop()[source]

Stop the Sprite’s motion

strafe(speed: float = 1.0)[source]

Set a sprites position perpendicular to its angle by speed :param speed: speed factor

property texture
property top

Return the y coordinate of the top of the sprite.

turn_left(theta: float = 90)[source]
turn_right(theta: float = 90)[source]
update()[source]

Update the sprite.

update_animation(delta_time: float = 0.016666666666666666)[source]

Override this to add code that will change what image is shown, so the sprite can be animated.

property width

Get the width of the sprite.

arcade.get_distance_between_sprites(sprite1: arcade.Sprite, sprite2: arcade.Sprite) → float[source]

Returns the distance between the center of two given sprites :param Sprite sprite1: Sprite one :param Sprite sprite2: Sprite two :return: Distance :rtype: float

SpriteList Commands

This module provides functionality to manage Sprites in a list.

class arcade.SpriteList(use_spatial_hash=False, spatial_hash_cell_size=128, is_static=False)[source]

Bases: typing.Generic

append(item: T)[source]

Add a new sprite to the list.

Parameters

item (Sprite) – Sprite to add to the list.

property center

Get the mean center coordinates of all sprites in the list.

draw()[source]

Draw this list of sprites.

dump()[source]
move(change_x: float, change_y: float)[source]

Moves all Sprites in the list by the same amount.

Parameters
  • change_x (float) – Amount to change all x values by

  • change_y (float) – Amount to change all y values by

next_texture_id = 0
pop() → arcade.Sprite[source]

Pop off the last sprite in the list.

preload_textures(texture_names: List)[source]

Preload a set of textures that will be used for sprites in this sprite list.

Parameters

texture_names (array) – List of file names to load in as textures.

remove(item: T)[source]

Remove a specific sprite from the list. :param Sprite item: Item to remove from the list

rescale(factor: float) → None[source]

Rescale all sprites in the list relative to the spritelists center.

update()[source]

Call the update() method on each sprite in the list.

update_angle(sprite: arcade.Sprite)[source]

Called by the Sprite class to update the angle in this sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

update_animation(delta_time: float = 0.016666666666666666)[source]
update_location(sprite: arcade.Sprite)[source]

Called by the Sprite class to update the location in this sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

update_position(sprite: arcade.Sprite)[source]

Called by the Sprite class to update position, angle, size and color of the specified sprite. Necessary for batch drawing of items.

Parameters

sprite (Sprite) – Sprite to update.

update_texture(_sprite)[source]

Make sure we update the texture for this sprite for the next batch drawing

arcade.get_closest_sprite(sprite: arcade.Sprite, sprite_list: arcade.SpriteList) → Optional[Tuple[arcade.Sprite, float]][source]

Given a Sprite and SpriteList, returns the closest sprite, and its distance.

Parameters
  • sprite (Sprite) – Target sprite

  • sprite_list (SpriteList) – List to search for closest sprite.

Returns

Closest sprite.

Return type

Sprite

Physics Engines

Physics engines for top-down or platformers.

class arcade.PhysicsEnginePlatformer(player_sprite: arcade.Sprite, platforms: arcade.SpriteList, gravity_constant: float = 0.5, ladders: arcade.SpriteList = None)[source]

Bases: object

This class will move everything, and take care of collisions.

can_jump(y_distance=5) → bool[source]

Method that looks to see if there is a floor under the player_sprite. If there is a floor, the player can jump and we return a True.

Returns

True if there is a platform below us

Return type

bool

disable_multi_jump()[source]

Disables multi-jump.

Calling this function also removes the requirement to call increment_jump_counter() every time the player jumps.

enable_multi_jump(allowed_jumps: int)[source]

Enables multi-jump. allowed_jumps should include the initial jump. (1 allows only a single jump, 2 enables double-jump, etc)

If you enable multi-jump, you MUST call increment_jump_counter() every time the player jumps. Otherwise they can jump infinitely.

Parameters

allowed_jumps (int) –

increment_jump_counter()[source]

Updates the jump counter for multi-jump tracking

is_on_ladder()[source]
jump(velocity: int)[source]
update()[source]

Move everything and resolve collisions.

class arcade.PhysicsEngineSimple(player_sprite: arcade.Sprite, walls: arcade.SpriteList)[source]

Bases: object

This class will move everything, and take care of collisions.

update()[source]

Move everything and resolve collisions.

Sound Support

Sound library.

exception arcade.PlaysoundException[source]

Bases: Exception

class arcade.Sound(file_name: str)[source]

Bases: object

play()[source]
arcade.load_sound(file_name: str)[source]

Load a sound. Support for .wav files. If ffmpeg is available, will work with ogg and mp3 as well.

Parameters

file_name (str) – Name of the sound file to load.

Returns

Sound object

Return type

Sound

arcade.play_sound(sound: arcade.Sound)[source]

Play a sound.

Parameters

sound (Sound) – Sound loaded by load_sound. Do NOT use a string here for the filename.

arcade.stop_sound(sound: pyglet.media.codecs.base.Source)[source]

Stop a sound that is currently playing.

Parameters

sound

Tiled Map Support

Functions and classes for managing a map saved in the .tmx format.

Typically these .tmx maps are created using the Tiled Map Editor.

For more information, see the Platformer Tutorial.

arcade.tilemap.get_tilemap_layer(map_object: pytiled_parser.objects.TileMap, layer_name: str) → Optional[pytiled_parser.objects.Layer][source]

Given a TileMap and a layer name, this returns the TileLayer.

Parameters
  • map_object (pytiled_parser.objects.TileMap) – The map read in by the read_tmx function.

  • layer_name (str) – A string to match the layer name. Case sensitive.

Returns

A TileLayer, or None if no layer was found.

arcade.tilemap.process_layer(map_object: pytiled_parser.objects.TileMap, layer_name: str, scaling: float = 1, base_directory: str = '') → arcade.SpriteList[source]

This takes a map layer returned by the read_tmx function, and creates Sprites for it.

Parameters
  • map_object – The TileMap read in by read_tmx.

  • layer_name – The name of the layer that we are creating sprites for.

  • scaling – Scaling the layer up or down. (Note, any number besides 1 can create a tearing effect, if numbers don’t evenly divide.)

  • base_directory – Base directory of the file, that we start from to load images.

Returns

A SpriteList.

arcade.tilemap.read_tmx(tmx_file: str) → pytiled_parser.objects.TileMap[source]

Given a .tmx, this will read in a tiled map, and return a TiledMap object.

Given a tsx_file, the map will use it as the tileset. If tsx_file is not specified, it will use the tileset specified within the tmx_file.

Important: Tiles must be a “collection” of images.

Hitboxes can be drawn around tiles in the tileset editor, but only polygons are supported. (This is a great area for PR’s to improve things.)

Parameters

tmx_file (str) – String with name of our TMX file

Returns

Map

Return type

TiledMap