Arcade Package API

Submodules

Window Commands Module

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

Param:None
Returns:None
Raises:None
arcade.window_commands.finish_render()[source]

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

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.RED)
>>> arcade.start_render()
>>> # All the drawing commands go here
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.window_commands.get_window() → typing.Union[pyglet.window.win32.Win32Window, NoneType][source]

Return a handle to the current window.

Param:None
Return window:Handle to the current window.
Raises:None
arcade.window_commands.open_window(window_title: str, width: numbers.Number, height: numbers.Number, resizable: bool = False)[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.

Args:
window_title:Title of the window.
width:Width of the window.
height:Height of the window.
resizable:Whether the window can be user-resizable.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.quick_run(0.25)
arcade.window_commands.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.
Returns:None
Raises:None
>>> import arcade
>>> arcade.pause(0.25) # Pause 1/2 second
arcade.window_commands.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.

Args:
time_to_pause:Number of seconds to pause before automatically closing.
Returns:
None
Raises:
None

Example:

arcade.window_commands.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.window_commands.schedule(function_pointer: typing.Callable, interval: numbers.Number)[source]

Schedule a function to be automatically called every interval seconds.

Args:
function_pointer:
 Pointer to the function to be called.
interval:Interval to call the function.
Returns:
None
Raises:
None
arcade.window_commands.set_background_color(color: typing.List[int])[source]

This specifies the background color of the window.

Args:
color (tuple):List of 3 or 4 bytes in RGB/RGBA format.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.RED)
>>> arcade.start_render()
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.window_commands.set_viewport(left: numbers.Number, right: numbers.Number, bottom: numbers.Number, top: numbers.Number)[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.

Args:
left:Left-most (smallest) x value.
right:Right-most (largest) x value.
bottom:Bottom (smallest) y value.
top:Top (largest) y value.
Returns:
None
Raises:
None
Example:
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> set_viewport(-1, 1, -1, 1)
>>> arcade.quick_run(0.25)
arcade.window_commands.set_window(window: pyglet.window.win32.Win32Window)[source]

Set a handle to the current window.

Args:
window:Handle to the current window.
Returns:
None
Raises:
None
arcade.window_commands.start_render()[source]

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

Draw Commands Module

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

class arcade.draw_commands.Texture(texture_id: int, width: float, height: float)[source]

Bases: object

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

Attributes:
id:ID of the texture as assigned by OpenGL
width:Width of the texture image in pixels
height:Height of the texture image in pixels
class arcade.draw_commands.VertexBuffer(vbo_id: ctypes.c_ulong, size: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

Bases: object

This class represents a vertex buffer object.

Attributes:
vbo_id:ID of the vertex buffer as assigned by OpenGL
size:
width:
height:
color:
>>> import arcade
>>> x = VertexBuffer(0, 10, 10, 10, arcade.color.AERO_BLUE)
arcade.draw_commands.create_ellipse(width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]]) → arcade.draw_commands.VertexBuffer[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.

import arcade arcade.open_window(“Drawing Example”, 800, 600) arcade.set_background_color(arcade.color.WHITE) arcade.start_render() ellipse_a = arcade.create_ellipse(100, 100, arcade.color.RED) ellipse_b = arcade.create_ellipse(100, 100, (0, 255, 0, 127)) render_ellipse_filled(ellipse_a, 200, 200, 45) render_ellipse_filled(ellipse_b, 250, 250, 45) arcade.finish_render() arcade.quick_run(0.25)

arcade.draw_commands.create_rectangle(width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]]) → arcade.draw_commands.VertexBuffer[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.

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

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

Args:
center_x:x position that is the center of the arc.
center_y:y position that is the center of the arc.
width:width of the arc.
height:height of the arc.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
start_angle:start angle of the arc in degrees.
end_angle:end angle of the arc in degrees.
tilt_angle:angle the arc is tilted.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_arc_filled(150, 144, 15, 36, arcade.color.BOTTLE_GREEN, 90, 360, 45)
>>> color = (255, 0, 0, 127)
>>> arcade.draw_arc_filled(150, 154, 15, 36, color, 90, 360, 45)
>>> arcade.finish_render()
>>> arcade.close_window()
arcade.draw_commands.draw_arc_outline(center_x: float, center_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], start_angle: float, end_angle: float, border_width: float = 1, tilt_angle: float = 0)[source]

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

Args:
center_x:x position that is the center of the arc.
center_y:y position that is the center of the arc.
width:width of the arc.
height:height of the arc.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
start_angle:start angle of the arc in degrees.
end_angle:end angle of the arc in degrees.
border_width:width of line in pixels.
angle:angle the arc is tilted.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_arc_outline(150, 81, 15, 36, arcade.color.BRIGHT_MAROON, 90, 360)
>>> transparent_color = (255, 0, 0, 127)
>>> arcade.draw_arc_outline(150, 71, 15, 36, transparent_color, 90, 360)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_circle_filled(center_x: float, center_y: float, radius: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

Draw a filled-in circle.

Args:
center_x:x position that is the center of the circle.
center_y:y position that is the center of the circle.
radius:width of the circle.
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.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_circle_filled(420, 285, 18, arcade.color.GREEN)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_circle_outline(center_x: float, center_y: float, radius: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw the outline of a circle.

Args:
center_x:x position that is the center of the circle.
center_y:y position that is the center of the circle.
radius:width of the circle.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the circle outline in pixels.
num_segments:float of triangle segments that make up this circle. Higher is better quality, but slower render time.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_circle_outline(300, 285, 18, arcade.color.WISTERIA, 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_ellipse_filled(center_x: float, center_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0)[source]

Draw a filled in ellipse.

Args:
center_x:x position that is the center of the circle.
center_y:y position that is the center of the circle.
height:height of the ellipse.
width:width of the ellipse.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
angle:Angle in degrees to tilt the ellipse.
num_segments:float of triangle segments that make up this circle. Higher is better quality, but slower render time.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_ellipse_filled(60, 81, 15, 36, arcade.color.AMBER)
>>> color = (127, 0, 127, 127)
>>> arcade.draw_ellipse_filled(60, 144, 15, 36, color, 45)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_ellipse_outline(center_x: float, center_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0)[source]

Draw the outline of an ellipse.

Args:
center_x:x position that is the center of the circle.
center_y:y position that is the center of the circle.
height:height of the ellipse.
width:width of the ellipse.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the circle outline in pixels.
tilt_angle:Angle in degrees to tilt the ellipse.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_ellipse_outline(540, 273, 15, 36, arcade.color.AMBER, 3)
>>> color = (127, 0, 127, 127)
>>> arcade.draw_ellipse_outline(540, 336, 15, 36, color, 3, 45)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_line(start_x: float, start_y: float, end_x: float, end_y: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a line.

Args:
start_x:x position of line starting point.
start_y:y position of line starting point.
end_x:x position of line ending point.
end_y:y position of line ending point.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the line in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_line(270, 495, 300, 450, arcade.color.WOOD_BROWN, 3)
>>> color = (127, 0, 127, 127)
>>> arcade.draw_line(280, 495, 320, 450, color, 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_line_strip(point_list: typing.Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a line strip. A line strip is a set of continuously connected line segments.

Args:
point_list:List of points making up the line. 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.
border_width:Width of the line in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((510, 450), (570, 450), (510, 480), (570, 480), (510, 510), (570, 510))
>>> arcade.draw_line_strip(point_list, arcade.color.TROPICAL_RAIN_FOREST, 3)
>>> color = (127, 0, 127, 127)
>>> point_list = ((510, 455), (570, 455), (510, 485), (570, 485), (510, 515), (570, 515))
>>> arcade.draw_line_strip(point_list, color, 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_lines(point_list: typing.Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a set of lines.

Draw a line between each pair of points specified.

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.
border_width:Width of the line in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((390, 450), (450, 450), (390, 480), (450, 480), (390, 510), (450, 510))
>>> arcade.draw_lines(point_list, arcade.color.BLUE, 3)
>>> arcade.start_render()
>>> point_list = ((390, 450), (550, 450), (490, 480), (550, 480), (490, 510), (550, 510))
>>> arcade.draw_lines(point_list, (0, 0, 255, 127), 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_lrtb_rectangle_filled(left: float, right: float, top: float, bottom: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

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

Args:
left:The x coordinate of the left edge of the rectangle.
right:The x coordinate of the right edge of the rectangle.
top:The y coordinate of the top of the rectangle.
bottom:The y coordinate of the rectangle bottom.
color:The color of the rectangle.
border_width:The width of the border in pixels. Defaults to one.
Returns:
None
Raises:
AttributeErrror:
 Raised if left > right or top < bottom.
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.start_render()
>>> arcade.draw_lrtb_rectangle_filled(1, 2, 3, 1, arcade.color.BLACK)
>>> arcade.draw_lrtb_rectangle_filled(2, 1, 3, 1, arcade.color.BLACK)
Traceback (most recent call last):
    ...
AttributeError: Left coordinate 2 must be less than or equal to the right coordinate 1
>>> arcade.draw_lrtb_rectangle_filled(1, 2, 3, 4, arcade.color.BLACK)
Traceback (most recent call last):
    ...
AttributeError: Bottom coordinate 4 must be less than or equal to the top coordinate 3
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_lrtb_rectangle_outline(left: float, right: float, top: float, bottom: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

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

Args:
left:The x coordinate of the left edge of the rectangle.
right:The x coordinate of the right edge of the rectangle.
top:The y coordinate of the top of the rectangle.
bottom:The y coordinate of the rectangle bottom.
color:The color of the rectangle.
border_width:The width of the border in pixels. Defaults to one.
Returns:
None
Raises:
AttributeErrror:
 Raised if left > right or top < bottom.
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.start_render()
>>> arcade.draw_lrtb_rectangle_outline(100, 100, 100, 100,         arcade.color.BLACK, 5)
>>> arcade.draw_lrtb_rectangle_outline(190, 180, 100, 100,         arcade.color.BLACK, 5)
Traceback (most recent call last):
    ...
AttributeError: Left coordinate must be less than or equal to the right coordinate
>>> arcade.draw_lrtb_rectangle_outline(170, 180, 100, 200,         arcade.color.BLACK, 5)
Traceback (most recent call last):
    ...
AttributeError: Bottom coordinate must be less than or equal to the top coordinate
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_parabola_filled(start_x: float, start_y: float, end_x: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0)[source]

Draws a filled in parabola.

Args:
start_x:The starting x position of the parabola
start_y:The starting y position of the parabola
end_x:The ending x position of the parabola
height:The height of the parabola
color:The color of the parabola
tilt_angle:The angle of the tilt of the parabola
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_parabola_filled(150, 150, 200, 50, arcade.color.BOTTLE_GREEN)
>>> color = (255, 0, 0, 127)
>>> arcade.draw_parabola_filled(160, 160, 210, 50, color)
>>> arcade.finish_render()
>>> arcade.close_window()
arcade.draw_commands.draw_parabola_outline(start_x: float, start_y: float, end_x: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0)[source]

Draws the outline of a parabola.

Args:
start_x:The starting x position of the parabola
start_y:The starting y position of the parabola
end_x:The ending x position of the parabola
height:The height of the parabola
color:The color of the parabola
border_width:The width of the parabola
tile_angle:The angle of the tilt of the parabola
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_parabola_outline(150, 150, 200, 50, arcade.color.BOTTLE_GREEN, 10, 15)
>>> color = (255, 0, 0, 127)
>>> arcade.draw_parabola_outline(160, 160, 210, 50, color, 20)
>>> arcade.finish_render()
>>> arcade.close_window()
arcade.draw_commands.draw_point(x: float, y: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], size: float)[source]

Draw a point.

Args:
x:x position of point.
y:y position of point.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
size:Size of the point in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_point(60, 495, arcade.color.RED, 10)
>>> arcade.draw_point(70, 495, (255, 0, 0, 127), 10)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_points(point_list: typing.Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], size: float = 1)[source]

Draw a set of points.

Args:
point_list:List of points 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.
size:Size of the point in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((165, 495), (165, 480), (165, 465), (195, 495), (195, 480), (195, 465))
>>> arcade.draw_points(point_list, arcade.color.ZAFFRE, 10)
>>> arcade.draw_points(point_list, make_transparent_color(arcade.color.ZAFFRE, 127), 10)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_polygon_filled(point_list: typing.Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.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
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((150, 240), (165, 240), (180, 255), (180, 285), (165, 300), (150, 300))
>>> arcade.draw_polygon_filled(point_list, arcade.color.SPANISH_VIOLET)
>>> arcade.draw_polygon_filled(point_list, make_transparent_color(arcade.color.SPANISH_VIOLET, 127))
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_polygon_outline(point_list: typing.Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

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

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.
border_width:Width of the line in pixels.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((30, 240), (45, 240), (60, 255), (60, 285), (45, 300), (30, 300))
>>> arcade.draw_polygon_outline(point_list, arcade.color.SPANISH_VIOLET, 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_rectangle_filled(center_x: float, center_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0)[source]

Draw a filled-in rectangle.

Args:
center_x:x coordinate of rectangle center.
center_y:y coordinate of rectangle center.
width:width of the rectangle.
height:height of the rectangle.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
angle:rotation of the rectangle. Defaults to zero.

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_rectangle_filled(390, 150, 45, 105, arcade.color.BLUSH)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_rectangle_outline(center_x: float, center_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0)[source]

Draw a rectangle outline.

Args:
x:x coordinate of top left rectangle point.
y:y coordinate of top left rectangle point.
width:width of the rectangle.
height:height of the rectangle.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:width of the lines, in pixels.
angle:rotation of the rectangle. Defaults to zero.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_rectangle_outline(278, 150, 45, 105, arcade.color.BRITISH_RACING_GREEN, 2)
>>> arcade.draw_rectangle_outline(278, 150, 45, 105, (100, 200, 100, 255))
>>> arcade.draw_rectangle_outline(278, 150, 45, 105, arcade.color.BRITISH_RACING_GREEN, 5, 45)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_text(text: str, start_x: float, start_y: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], font_size: float = 12, width: int = 2000, align='left', font_name=('Calibri', 'Arial'), bold: bool = False, italic: bool = False, anchor_x='left', anchor_y='baseline', rotation=0)[source]

Draw text to the screen.

Args:
text:Text to display.
start_x:x coordinate of top left text point.
start_y:y coordinate of top left text point.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

Example:

>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_text("Text Example", 250, 300, arcade.color.BLACK, 10)
>>> arcade.draw_text("Text Example", 250, 300, (0, 0, 0, 100), 10)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_texture_rectangle(center_x: float, center_y: float, width: float, height: float, texture: arcade.draw_commands.Texture, angle: float = 0, alpha: float = 1, transparent: bool = True)[source]

Draw a textured rectangle on-screen.

Args:
center_x:x coordinate of rectangle center.
center_y:y coordinate of rectangle center.
width:width of the rectangle.
height:height of the rectangle.
texture:identifier of texture returned from load_texture() call
angle:rotation of the rectangle. Defaults to zero.
alpha:Transparency of image.
Returns:
None
Raises:
None
Example:
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_text("draw_bitmap", 483, 3, arcade.color.BLACK, 12)
>>> name = "examples/images/playerShip1_orange.png"
>>> texture = arcade.load_texture(name)
>>> scale = .6
>>> arcade.draw_texture_rectangle(540, 120, scale * texture.width, scale * texture.height, texture, 0)
>>> arcade.draw_texture_rectangle(540, 60, scale * texture.width, scale * texture.height, texture, 90)
>>> arcade.draw_texture_rectangle(540, 60, scale * texture.width, scale * texture.height, texture, 90, 1, False)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_triangle_filled(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

Draw a filled in triangle.

Args:
x1:x value of first coordinate.
y1:y value of first coordinate.
x2:x value of second coordinate.
y2:y value of second coordinate.
x3:x value of third coordinate.
y3:y value of third coordinate.
color:Color of triangle.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.start_render()
>>> arcade.draw_triangle_filled(1, 2, 3, 4, 5, 6, arcade.color.BLACK)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_triangle_outline(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a the outline of a triangle.

Args:
x1:x value of first coordinate.
y1:y value of first coordinate.
x2:x value of second coordinate.
y2:y value of second coordinate.
x3:x value of third coordinate.
y3:y value of third coordinate.
color:Color of triangle.
border_width:Width of the border in pixels. Defaults to 1.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.start_render()
>>> arcade.draw_triangle_outline(1, 2, 3, 4, 5, 6, arcade.color.BLACK, 5)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_xywh_rectangle_filled(top_left_x: float, top_left_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

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

Args:
top_left_x:The x coordinate of the left edge of the rectangle.
top_left_y:The y coordinate of the top of the rectangle.
width:The width of the rectangle.
height:The height of the rectangle.
color:The color of the rectangle.
border_width:The width of the border in pixels. Defaults to one.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.start_render()
>>> arcade.draw_xywh_rectangle_filled(1, 2, 3, 4, arcade.color.BLACK)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_xywh_rectangle_outline(top_left_x: float, top_left_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

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

Args:
top_left_x:The x coordinate of the left edge of the rectangle.
top_left_y:The y coordinate of the top of the rectangle.
width:The width of the rectangle.
height:The height of the rectangle.
color:The color of the rectangle.
border_width:The width of the border in pixels. Defaults to one.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.start_render()
>>> arcade.draw_xywh_rectangle_outline(1, 2, 10, 10, arcade.color.BLACK, 5)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_xywh_rectangle_textured(top_left_x: float, top_left_y: float, width: float, height: float, texture: arcade.draw_commands.Texture)[source]
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> arcade.start_render()
>>> name = "examples/images/meteorGrey_big1.png"
>>> texture1 = load_texture(name, 1, 1, 50, 50)
>>> arcade.draw_xywh_rectangle_textured(1, 2, 10, 10, texture1)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.load_texture(file_name: str, x: float = 0, y: float = 0, width: float = 0, height: float = 0, scale: float = 1) → arcade.draw_commands.Texture[source]

Load image from disk and create a texture.

Args:
filename (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.
scale (float):Scale factor to apply on the new texture.
Returns:
The new texture.
Raises:
None
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> name = "examples/images/meteorGrey_big1.png"
>>> texture1 = load_texture(name, 1, 1, 50, 50)
>>> texture2 = load_texture(name, 1, 1, 50, 50)
>>> texture = load_texture(name, 200, 1, 50, 50)
Traceback (most recent call last):
...
ValueError: Can't load texture starting at an x of 200 when the image is only 101 across.
>>> texture = load_texture(name, 1, 50, 50, 50)
Traceback (most recent call last):
...
ValueError: Can't load texture ending at an y of 100 when the image is only 84 high.
>>> texture = load_texture(name, 1, 150, 50, 50)
Traceback (most recent call last):
...
ValueError: Can't load texture starting at an y of 150 when the image is only 84 high.
>>> texture = load_texture(name, 0, 0, 400, 50)
Traceback (most recent call last):
...
ValueError: Can't load texture ending at an x of 400 when the image is only 101 wide.
>>> arcade.close_window()
arcade.draw_commands.load_textures(file_name: str, image_location_list: typing.Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], mirrored: bool = False, flipped: bool = False) → typing.List[typing.Texture][source]

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

Args:
file_name:Name of the file.
image_location_list:
 List of image locations. Each location should be a list of four floats. [x, y, width, height].
mirrored=False:If set to true, the image is mirrored left to right.
flipped=False:If set to true, the image is flipped upside down.
Returns:
list:List of textures loaded.
Raises:
SystemError:
>>> import arcade
>>> arcade.open_window("Drawing Example", 800, 600)
>>> image_location_list = [[591, 5, 64, 93],
...                        [655, 10, 75, 88],
...                        [730, 7, 54, 91],
...                        [784, 3, 59, 95],
...                        [843, 6, 56, 92]]
>>> texture_info_list = arcade.load_textures("examples/images/character_sheet.png", image_location_list)
>>> image_location_list = [[5600, 0, 0, 0]]
>>> texture_info_list = arcade.load_textures("examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Texture has a width of 0, must be > 0.
>>> image_location_list = [[2000, 0, 20, 20]]
>>> texture_info_list = arcade.load_textures("examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Can't load texture starting at an x of 2000 when the image is only 1377 across.
>>> image_location_list = [[500, 500, 20, 20]]
>>> texture_info_list = arcade.load_textures("examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Can't load texture starting at an y of 500 when the image is only 98 high.
>>> image_location_list = [[1300, 0, 100, 20]]
>>> texture_info_list = arcade.load_textures("examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Can't load texture ending at an x of 1400 when the image is only 1377 wide.
>>> image_location_list = [[500, 50, 50, 50]]
>>> texture_info_list = arcade.load_textures("examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Can't load texture ending at an y of 100 when the image is only 98 high.
>>> image_location_list = [[0, 0, 50, 50]]
>>> texture_info_list = arcade.load_textures("examples/images/character_sheet.png", image_location_list, mirrored=True, flipped=True)
>>> arcade.close_window()
arcade.draw_commands.make_transparent_color(color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], transparency: float)[source]

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

arcade.draw_commands.render_ellipse_filled(shape: arcade.draw_commands.VertexBuffer, center_x: float, center_y: float, angle: float = 0)[source]

Render an ellipse previously created with the create_ellipse function.

arcade.draw_commands.render_rectangle_filled(shape: arcade.draw_commands.VertexBuffer, center_x: float, center_y: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0)[source]

Render a rectangle previously created by the create_rectangle command.

arcade.draw_commands.trim_image(image: <module 'PIL.Image' from 'c:\\python35\\lib\\site-packages\\PIL\\Image.py'>) → <module 'PIL.Image' from 'c:\\python35\\lib\\site-packages\\PIL\\Image.py'>[source]

Returns an image with extra whitespace cropped out.

>>> name = "examples/images/playerShip1_orange.png"
>>> source_image = PIL.Image.open(name)
>>> cropped_image = trim_image(source_image)
>>> print(source_image.height, cropped_image.height)
75 75

Application Class Module

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

class arcade.application.Window(width: float, height: float, title: str = 'Arcade Window', resizable: bool = False)[source]

Bases: pyglet.window.win32.Win32Window

Window class

animate(delta_time: float)[source]

Move everything.

Args:
dt (float):Time interval since the last time the function was called.
get_location() → typing.Tuple[int, int][source]

Return the X/Y coordinates of the window

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

Override this function to add mouse button functionality.

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

Override this function to add mouse functionality.

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

Override this function to add mouse button functionality.

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

Override this function to add mouse button functionality.

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

Wrap the Pyglet window call to set maximum size

Args:
width:width in pixels.
height:height in pixels.
Returns:
None
Raises:
ValueError

Example:

>>> import arcade
>>> window = arcade.Window(200, 100, resizable=True)
>>> window.set_max_size(200, 200)
>>> window.close()
set_min_size(width: float, height: float)[source]

Wrap the Pyglet window call to set minimum size

Args:
width:width in pixels.
height:height in pixels.
Returns:
None
Raises:
ValueError

Example:

>>> import arcade
>>> window = arcade.Window(200, 100, resizable=True)
>>> window.set_min_size(200, 200)
>>> window.close()
set_size(width: float, height: float)[source]

Ignore the resizable flag and set the size

set_update_rate(rate: float)[source]

Set how often the screen should be updated.

Geometry Module

Functions for calculating geometry.

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

Return True if two polygons intersect.

Args:
poly_a (tuple):List of points that define the first polygon.
poly_b (tuple):List of points that define the second polygon.
Returns:
bool
Raises:
None
Example:
>>> import arcade
>>> poly1 = ((0.1, 0.1), (0.2, 0.1), (0.2, 0.2), (0.1, 0.2))
>>> poly2 = ((0.15, 0.1), (0.25, 0.1), (0.25, 0.25), (0.15, 0.25))
>>> poly3 = ((0.3, 0.1), (0.4, 0.1), (0.4, 0.2), (0.3, 0.2))
>>> test1 = arcade.are_polygons_intersecting(poly1, poly2)
>>> test2 = arcade.are_polygons_intersecting(poly2, poly3)
>>> test3 = arcade.are_polygons_intersecting(poly1, poly3)
>>> print(test1, test2, test3)
True False False
arcade.geometry.check_for_collision(sprite1: arcade.sprite.Sprite, sprite2: arcade.sprite.Sprite) → bool[source]

Check for a collision between two sprites.

>>> import arcade
>>> scale = 1
>>> filename = "examples/images/meteorGrey_big1.png"
>>> sprite_1 = arcade.Sprite(filename, scale)
>>> sprite_1.center_x = 0
>>> sprite_1.center_y = 0
>>> sprite_2 = arcade.Sprite(filename, scale)
>>> sprite_2.center_x = 40
>>> sprite_2.center_y = 40
>>> result = check_for_collision(sprite_1, sprite_2)
>>> sprite_3 = arcade.Sprite(filename, scale)
>>> sprite_3.center_x = 90
>>> sprite_3.center_y = 90
>>> result_1 = check_for_collision(sprite_1, sprite_2)
>>> result_2 = check_for_collision(sprite_2, sprite_3)
>>> result_3 = check_for_collision(sprite_1, sprite_3)
>>> print(result_1, result_2, result_3)
True True False
arcade.geometry.check_for_collision_with_list(sprite1: arcade.sprite.Sprite, sprite_list: arcade.sprite.SpriteList) → typing.List[arcade.sprite.Sprite][source]

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

>>> import arcade
>>> scale = 1
>>> sprite_list = arcade.SpriteList()
>>> filename = "examples/images/meteorGrey_big1.png"
>>> main_sprite = arcade.Sprite(filename, scale)
>>> main_sprite.center_x = 0
>>> main_sprite.center_y = 0
>>> sprite = arcade.Sprite(filename, scale)
>>> sprite.center_x = 40
>>> sprite.center_y = 40
>>> sprite_list.append(sprite)
>>> sprite = arcade.Sprite(filename, scale)
>>> sprite.center_x = 100
>>> sprite.center_y = 100
>>> sprite_list.append(sprite)
>>> collision_list = arcade.check_for_collision_with_list(main_sprite, sprite_list)
>>> print(len(collision_list))
1

Shape Objects Module

Various shapes for arcade games.

class arcade.shape_objects.Arc(center_x: float, center_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), start_angle: float = 0, end_angle: float = 180, border_width: float = 0, tilt_angle: float = 0)[source]

Bases: arcade.shape_objects.Shape

draw()[source]
update()[source]
class arcade.shape_objects.Circle(center_x: float, center_y: float, radius: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), border_width: float = 0)[source]

Bases: arcade.shape_objects.Shape

Class that represents an Circle.

draw()[source]
class arcade.shape_objects.Ellipse(center_x: float, center_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), tilt_angle: float = 0)[source]

Bases: arcade.shape_objects.Shape

Class that represents an Ellipse.

draw()[source]
class arcade.shape_objects.Line(start_x: float, start_y: float, end_x: float, end_y: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), width: float = 1)[source]

Bases: arcade.shape_objects.Shape

draw()[source]
update()[source]
class arcade.shape_objects.Parabola(start_x: float, start_y: float, end_x: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), border_width: float = 0, tilt_angle: float = 0)[source]

Bases: arcade.shape_objects.Shape

class arcade.shape_objects.Point(center_x: float, center_y: float, size: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0))[source]

Bases: arcade.shape_objects.Shape

Class that represents an Point.

draw()[source]
class arcade.shape_objects.Polygon(point_list: typing.Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), border_width: float = 0)[source]

Bases: arcade.shape_objects.Shape

draw()[source]
update()[source]
class arcade.shape_objects.Rectangle(center_x: float, center_y: float, width: float, height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), border_width: float = 0, tilt_angle: float = 0)[source]

Bases: arcade.shape_objects.Shape

draw()[source]
class arcade.shape_objects.Shape(center_x: float, center_y: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), tilt_angle: float = 0)[source]

Bases: object

draw()[source]
update()[source]
class arcade.shape_objects.Square(center_x: float, center_y: float, width_and_height: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), border_width: float = 0, tilt_angle: float = 0)[source]

Bases: arcade.shape_objects.Rectangle

draw()[source]
class arcade.shape_objects.Text(text: str, center_x: float, center_y: float, size: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0))[source]

Bases: arcade.shape_objects.Shape

Class that represents a text label.

draw()[source]
class arcade.shape_objects.Triangle(first_x: float, first_y: float, second_x: float, second_y: float, third_x: float, third_y: float, color: typing.Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]] = (0, 255, 0), border_width: float = 0)[source]

Bases: arcade.shape_objects.Shape

Class that represents a triangle.

draw()[source]
arcade.shape_objects.draw_all(shape_list: typing.Iterable[arcade.shape_objects.Shape])[source]
arcade.shape_objects.master_draw(shape_object: arcade.shape_objects.Shape)[source]
arcade.shape_objects.update_all(shape_list: typing.Iterable[arcade.shape_objects.Shape])[source]

Sprite Module

This module manages all of the code around Sprites.

class arcade.sprite.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

Sprite for platformer games that supports animations.

update_animation()[source]

Logic for selecting the proper texture to use.

class arcade.sprite.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

Sprite for platformer games that supports animations.

update_animation()[source]

Logic for selecting the proper texture to use.

class arcade.sprite.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)[source]

Bases: object

Class that represents a ‘sprite’ on-screen.

Attributes:
scale:Scale the sprite. Default is 1. Setting to 0.5 would halve the width and height.
center_x:x coordinate of the sprite’s center.
center_y:y coordinate of the sprite’s center.
angle:Angle at which the sprite is drawn. 0 is default, 180 is upside-down.
change_x:Movement vector, in the x direction.
change_y:Movement vector, in the y direction.
change_angle:Change in rotation.
alpha:Transparency. 1 is solid, 0 is fully transparent (invisible).
transparent:Set to True if this sprite can be transparent.
sprite_lists:List of all the sprite lists this sprite is part of.
textures:List of textures associated with this sprite.
cur_texture_index:
 Index of current texture being used.
Example:
>>> import arcade
>>> arcade.open_window("Sprite Example", 800, 600)
>>> SCALE = 1
>>> # Test creating an empty sprite
>>> empty_sprite = arcade.Sprite()
>>> # Create a sprite with an image
>>> filename = "examples/images/playerShip1_orange.png"
>>> ship_sprite = arcade.Sprite(filename, SCALE)
>>> # Draw the sprite
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> ship_sprite.draw()
>>> arcade.finish_render()
>>> # Move the sprite
>>> ship_sprite.change_x = 1
>>> ship_sprite.change_y = 1
>>> ship_sprite.update() # Move/update the ship
>>> # Remove the sprite
>>> ship_sprite.kill()
>>> ship_sprite = arcade.Sprite(filename, SCALE, image_height=-1)
Traceback (most recent call last):
...
ValueError: Height entered is less than zero. Height must be a positive float.
>>> arcade.quick_run(0.25)
angle

Get the angle of the sprite’s rotation.

append_texture(texture: arcade.draw_commands.Texture)[source]

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

bottom

Return the y coordinate of the bottom of the sprite.

>>> import arcade
>>> arcade.open_window("Sprite Example", 800, 600)
>>> scale = 1.0
>>> ship_sprite = arcade.Sprite("examples/images/playerShip1_orange.png", scale)
>>> ship_sprite.center_y = 0.0
>>> print(ship_sprite.bottom)
-37.5
>>> ship_sprite.bottom = 1.0
>>> print(ship_sprite.bottom)
1.0
>>> arcade.quick_run(0.25)
center_x

Get the center x coordinate of the sprite.

center_y

Get the center y coordinate of the sprite.

change_x

Get the velocity in the x plane of the sprite.

change_y

Get the velocity in the y plane of the sprite.

draw()[source]

Draw the sprite.

get_points() → typing.List[typing.List[float]][source]

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

get_texture() → int[source]

This returns the index of which texture is being displayed.

kill()[source]

Remove the sprite from all sprite lists.

left

Left-most coordinate.

Example:
>>> import arcade
>>> arcade.open_window("Sprite Example", 800, 600)
>>> scale = 1.0
>>> ship_sprite = arcade.Sprite("examples/images/playerShip1_orange.png", scale)
>>> ship_sprite.center_x = 0.0
>>> print(ship_sprite.left)
-49.5
>>> ship_sprite.left = 1.0
>>> print(ship_sprite.left)
1.0
>>> arcade.quick_run(0.25)
points

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

right

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

Example:
>>> import arcade
>>> arcade.open_window("Sprite Example", 800, 600)
>>> scale = 1.0
>>> ship_sprite = arcade.Sprite("examples/images/playerShip1_orange.png", scale)
>>> ship_sprite.center_x = 0.0
>>> print(ship_sprite.right)
49.5
>>> ship_sprite.right = 1.0
>>> print(ship_sprite.right)
1.0
>>> arcade.quick_run(0.25)
set_points(points: typing.Sequence[typing.Sequence[float]])[source]
set_position(center_x: float, center_y: float)[source]

Set a sprite’s position

set_texture(texture_no: int)[source]

Assuming ‘texture’ is a list of textures, this sets which texture index should be displayed. It also resets the width and height based on the scale of the texture.

texture

Return the texture that the sprite uses.

top

Return the y coordinate of the top of the sprite.

>>> import arcade
>>> arcade.open_window("Sprite Example", 800, 600)
>>> scale = 1.0
>>> ship_sprite = arcade.Sprite("examples/images/playerShip1_orange.png", scale)
>>> ship_sprite.center_y = 0.0
>>> print(ship_sprite.top)
37.5
>>> ship_sprite.top = 1.0
>>> print(ship_sprite.top)
1.0
>>> arcade.quick_run(0.25)
update()[source]

Update the sprite.

update_animation()[source]

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

class arcade.sprite.SpriteList[source]

Bases: object

List of sprites.

Unit Test:
>>> import arcade
>>> import random
>>> arcade.open_window("Sprite Example", 600, 600)
>>> scale = 1
>>> meteor_list = arcade.SpriteList()
>>> filename = "examples/images/meteorGrey_big1.png"
>>> for i in range(100):
...     meteor = arcade.Sprite(filename, scale)
...     meteor.center_x = random.random() * 2 - 1
...     meteor.center_y = random.random() * 2 - 1
...     meteor_list.append(meteor)
>>> meteor_list.remove(meteor) # Remove last meteor, just to test
>>> m = meteor_list.pop() # Remove another meteor, just to test
>>> meteor_list.update() # Call update on all items
>>> print(len(meteor_list))
98
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> meteor_list.draw(fast=False)
>>> arcade.finish_render()
>>> for meteor in meteor_list:
...     meteor.kill()
>>> arcade.quick_run(0.25)
append(item: arcade.sprite.Sprite)[source]

Add a new sprite to the list.

draw(fast: bool = True)[source]

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

pop() → arcade.sprite.Sprite[source]

Pop off the last sprite in the list.

remove(item: arcade.sprite.Sprite)[source]

Remove a specific sprite from the list.

update()[source]

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

update_animation()[source]

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

Physics Engines Module

Physics engines for top-down or platformers.

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

Bases: object

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

can_jump() → 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.

update()[source]

Move everything and resolve collisions.

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

Bases: object

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

update()[source]

Move everything and resolve collisions.

Sound Module

Small abstraction around the sound library.

arcade.sound.load_sound(filename: str) → typing.Any[source]

Load a sound and get it ready to play.

arcade.sound.load_sound_library()[source]

Special code for Windows so we grab the proper avbin from our directory. Otherwise hope the correct package is installed.

arcade.sound.play_sound(sound: typing.Any)[source]

Play a previously loaded sound.