Arcade Package API¶
This page documents the Application Programming Interface (API) for the Python Arcade library. Soo also:
Arcade Sub Modules
Main Arcade Module Package API¶
The Arcade Library
A Python simple, easy to use module for creating 2D games.
-
class
arcade.
AStarBarrierList
(moving_sprite: arcade.Sprite, blocking_sprites: arcade.SpriteList, grid_size: int, left: int, right: int, bottom: int, top: int)[source]¶ Bases:
object
Class that manages a list of barriers that can be encountered during A* path finding.
-
__init__
(moving_sprite: arcade.Sprite, blocking_sprites: arcade.SpriteList, grid_size: int, left: int, right: int, bottom: int, top: int)[source]¶ - Parameters
moving_sprite (Sprite) – Sprite that will be moving
blocking_sprites (SpriteList) – Sprites that can block movement
grid_size (int) – Size of the grid, in pixels
left (int) – Left border of playing field
right (int) – Right border of playing field
bottom (int) – Bottom of playing field
top (int) – Top of playing field
-
-
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. These can be automatically created by the Tiled Map Editor.
-
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
Deprecated class for periodically updating sprite animations. Use AnimatedTimeBasedSprite instead.
-
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 walking animations. Make sure to call update_animation after loading the animations so the initial texture can be set. Or manually set it. For a better example, see: http://arcade.academy/examples/platformer.html#animate-character
-
class
arcade.
AnimationKeyframe
(tile_id: int, duration: int, texture: arcade.texture.Texture)[source]¶ Bases:
object
Used in animated sprites.
-
texture
: arcade.texture.Texture¶
-
-
class
arcade.
ArcadeContext
(window: pyglet.window.BaseWindow)[source]¶ Bases:
arcade.gl.context.Context
An OpenGL context implementation for Arcade with added custom features. This context is normally accessed thought
arcade.Window.ctx
.Pyglet users can use the base Context class and extend that as they please.
This is part of the low level rendering API in arcade and is mainly for more advanced usage
-
__init__
(window: pyglet.window.BaseWindow)[source]¶ - Parameters
window (pyglet.window.Window) – The pyglet window
-
load_program
(*, vertex_shader: Union[str, pathlib.Path], fragment_shader: Union[str, pathlib.Path] = None, geometry_shader: Union[str, pathlib.Path] = None, tess_control_shader: Union[str, pathlib.Path] = None, tess_evaluation_shader: Union[str, pathlib.Path] = None, defines: dict = None) → arcade.gl.program.Program[source]¶ Create a new program given a file names that contain the vertex shader and fragment shader. Note that fragment and geometry shader are optional for when transform shaders are loaded.
This method also supports the
:resources:
prefix. It’s recommended to use absolute paths, but not required.Example:
# The most common use case if having a vertex and fragment shader program = window.ctx.load_program( vertex_shader="vert.glsl", fragment_shader="frag.glsl", )
- Parameters
vertex_shader (Union[str,pathlib.Path]) – path to vertex shader
fragment_shader (Union[str,pathlib.Path]) – path to fragment shader (optional)
geometry_shader (Union[str,pathlib.Path]) – path to geometry shader (optional)
defines (dict) – Substitute
#define
values in the source
-
load_texture
(path: Union[str, pathlib.Path], *, flip: bool = True, build_mipmaps=False) → arcade.gl.texture.Texture[source]¶ Loads and creates an OpenGL 2D texture. Currently all textures are converted to RGBA.
Example:
texture = window.ctx.load_texture("background.png")
- Parameters
path (Union[str,pathlib.Path]) – Path to texture
flip (bool) – Flips the image upside down
build_mipmaps (bool) – Build mipmaps for the texture
-
property
projection_2d
¶ Get or set the global orthogonal projection for arcade.
This projection is used by sprites and shapes and is represented by four floats:
(left, right, bottom, top)
-
property
projection_2d_matrix
¶ Get the current projection matrix as a numpy array. This 4x4 float32 matrix is calculated when setting
projection_2d
.
-
-
arcade.
Color
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]
-
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.
EmitBurst
(count: int)[source]¶ Bases:
arcade.emitter.EmitController
Used to configure an Emitter to emit particles in one burst
-
class
arcade.
EmitController
[source]¶ Bases:
object
Base class for how a client configure the rate at which an Emitter emits Particles
Subclasses allow the client to control the rate and duration of emitting
-
class
arcade.
EmitInterval
(emit_interval: float)[source]¶ Bases:
arcade.emitter.EmitController
Base class used to configure an Emitter to have a constant rate of emitting. Will emit indefinitely.
-
class
arcade.
EmitMaintainCount
(particle_count: int)[source]¶ Bases:
arcade.emitter.EmitController
Used to configure an Emitter so it emits particles so that the given count is always maintained
-
class
arcade.
Emitter
(center_xy: Union[Tuple[float, float], List[float]], emit_controller: arcade.emitter.EmitController, particle_factory: Callable[[Emitter], arcade.particle.Particle], change_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), emit_done_cb: Callable[[Emitter], None] = None, reap_cb: Callable[], None] = None)[source]¶ Bases:
object
Emits and manages Particles over their lifetime. The foundational class in a particle system.
-
__init__
(center_xy: Union[Tuple[float, float], List[float]], emit_controller: arcade.emitter.EmitController, particle_factory: Callable[[Emitter], arcade.particle.Particle], change_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), emit_done_cb: Callable[[Emitter], None] = None, reap_cb: Callable[], None] = None)[source]¶
-
-
class
arcade.
EmitterIntervalWithCount
(emit_interval: float, particle_count: int)[source]¶ Bases:
arcade.emitter.EmitInterval
Configure an Emitter to emit particles with given interval, ending after emitting given number of particles
-
class
arcade.
EmitterIntervalWithTime
(emit_interval: float, lifetime: float)[source]¶ Bases:
arcade.emitter.EmitInterval
Configure an Emitter to emit particles with given interval, ending after given number of seconds
-
class
arcade.
EternalParticle
(filename_or_texture: Union[str, arcade.texture.Texture], change_xy: Union[Tuple[float, float], List[float]], center_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), angle: float = 0, change_angle: float = 0, scale: float = 1.0, alpha: int = 255, mutation_callback=None)[source]¶ Bases:
arcade.particle.Particle
Particle that has no end to its life
-
class
arcade.
FadeParticle
(filename_or_texture: Union[str, arcade.texture.Texture], change_xy: Union[Tuple[float, float], List[float]], lifetime: float, center_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), angle: float = 0, change_angle: float = 0, scale: float = 1.0, start_alpha: int = 255, end_alpha: int = 0, mutation_callback=None)[source]¶ Bases:
arcade.particle.LifetimeParticle
Particle that animates its alpha between two values during its lifetime
-
__init__
(filename_or_texture: Union[str, arcade.texture.Texture], change_xy: Union[Tuple[float, float], List[float]], lifetime: float, center_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), angle: float = 0, change_angle: float = 0, scale: float = 1.0, start_alpha: int = 255, end_alpha: int = 0, mutation_callback=None)[source]¶
-
-
arcade.
FilenameOrTexture
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Union[str, arcade.texture.Texture]
-
class
arcade.
LifetimeParticle
(filename_or_texture: Union[str, arcade.texture.Texture], change_xy: Union[Tuple[float, float], List[float]], lifetime: float, center_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), angle: float = 0, change_angle: float = 0, scale: float = 1.0, alpha: int = 255, mutation_callback=None)[source]¶ Bases:
arcade.particle.Particle
Particle that lives for a given amount of time and is then deleted
-
__init__
(filename_or_texture: Union[str, arcade.texture.Texture], change_xy: Union[Tuple[float, float], List[float]], lifetime: float, center_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), angle: float = 0, change_angle: float = 0, scale: float = 1.0, alpha: int = 255, mutation_callback=None)[source]¶
-
-
arcade.
NamedPoint
¶ alias of
arcade.arcade_types.Point
-
exception
arcade.
NoOpenGLException
[source]¶ Bases:
Exception
Exception when we can’t get an OpenGL 3.3+ context
-
class
arcade.
Particle
(filename_or_texture: Union[str, arcade.texture.Texture], change_xy: Union[Tuple[float, float], List[float]], center_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), angle: float = 0.0, change_angle: float = 0.0, scale: float = 1.0, alpha: int = 255, mutation_callback=None)[source]¶ Bases:
arcade.Sprite
Sprite that is emitted from an Emitter
-
__init__
(filename_or_texture: Union[str, arcade.texture.Texture], change_xy: Union[Tuple[float, float], List[float]], center_xy: Union[Tuple[float, float], List[float]] = (0.0, 0.0), angle: float = 0.0, change_angle: float = 0.0, scale: float = 1.0, alpha: int = 255, mutation_callback=None)[source]¶
-
-
class
arcade.
PhysicsEnginePlatformer
(player_sprite: arcade.Sprite, platforms: arcade.SpriteList, gravity_constant: float = 0.5, ladders: arcade.SpriteList = None)[source]¶ Bases:
object
Simplistic physics engine for use in a platformer. It is easier to get started with this engine than more sophisticated engines like PyMunk. Note, it does not currently handle rotation.
-
__init__
(player_sprite: arcade.Sprite, platforms: arcade.SpriteList, gravity_constant: float = 0.5, ladders: arcade.SpriteList = None)[source]¶ Create a physics engine for a platformer.
- Parameters
player_sprite (Sprite) – The moving sprite
platforms (SpriteList) – The sprites it can’t move through
gravity_constant (float) – Downward acceleration per frame
ladders (SpriteList) – Ladders the user can climb on
-
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
-
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) –
-
-
class
arcade.
PhysicsEngineSimple
(player_sprite: arcade.Sprite, walls: arcade.SpriteList)[source]¶ Bases:
object
Simplistic physics engine for use in games without gravity, such as top-down games. It is easier to get started with this engine than more sophisticated engines like PyMunk. Note, it does not currently handle rotation.
-
__init__
(player_sprite: arcade.Sprite, walls: arcade.SpriteList)[source]¶ Create a simple physics engine.
- Parameters
player_sprite (Sprite) – The moving sprite
walls (SpriteList) – The sprites it can’t move through
-
-
arcade.
Point
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Union[Tuple[float, float], List[float]]
-
arcade.
PointList
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Sequence[Union[Tuple[float, float], List[float]]]
-
class
arcade.
PymunkPhysicsEngine
(gravity=(0, 0), damping: float = 1.0)[source]¶ Bases:
object
Pymunk Physics Engine
-
DYNAMIC
= 0¶
-
KINEMATIC
= 1¶
-
MOMENT_INF
= inf¶
-
STATIC
= 2¶
-
add_collision_handler
(first_type: str, second_type: str, begin_handler: Callable = None, pre_handler: Callable = None, post_handler: Callable = None, separate_handler: Callable = None)[source]¶ Add code to handle collisions between objects.
-
add_sprite
(sprite: arcade.Sprite, mass: float = 1, friction: float = 0.2, elasticity: Optional[float] = None, moment=None, body_type=0, damping=None, gravity=None, max_velocity=None, max_horizontal_velocity=None, max_vertical_velocity=None, radius: float = 0, collision_type: str = 'default')[source]¶ Add a sprite to the physics engine.
-
add_sprite_list
(sprite_list, mass: float = 1, friction: float = 0.2, elasticity: Optional[float] = None, moment=None, body_type=0, collision_type=None)[source]¶ Add all sprites in a sprite list to the physics engine.
-
apply_opposite_running_force
(sprite: arcade.Sprite)[source]¶ If a sprite goes left while on top of a dynamic sprite, that sprite should get pushed to the right.
-
check_grounding
(sprite: arcade.Sprite)[source]¶ See if the player is on the ground. Used to see if we can jump.
-
get_physics_object
(sprite: arcade.Sprite) → arcade.pymunk_physics_engine.PymunkPhysicsObject[source]¶ Get the shape/body for a sprite.
-
get_sprite_for_shape
(shape) → Optional[arcade.Sprite][source]¶ Given a shape, what sprite is associated with it?
-
get_sprites_from_arbiter
(arbiter)[source]¶ Given a collision arbiter, return the sprites associated with the collision.
-
resync_sprites
()[source]¶ Set visual sprites to be the same location as physics engine sprites. Call this after stepping the pymunk physics engine
-
step
(delta_time: float = 0.016666666666666666, resync_sprites: bool = True)[source]¶ Tell the physics engine to perform calculations.
- Parameters
delta_time (float) – Time to move the simulation forward. Keep this value constant, do not use varying values for each step.
resync_sprites (bool) – Resynchronize Arcade graphical sprites to be at the same location as their Pymunk counterparts. If running multiple steps per frame, set this to false for the first steps, and true for the last step that’s part of the update.
-
-
class
arcade.
PymunkPhysicsObject
(body: pymunk.body.Body = None, shape: pymunk.shapes.Shape = None)[source]¶ Bases:
object
Object that holds pymunk body/shape for a sprite.
-
arcade.
RGB
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Union[Tuple[int, int, int], List[int]]
-
arcade.
RGBA
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Union[Tuple[int, int, int, int], List[int]]
-
arcade.
Rect
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Union[Tuple[float, float, float, float], List[float]]
-
arcade.
RectList
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Union[Tuple[Union[Tuple[float, float, float, float], List[float]], …], List[Union[Tuple[float, float, float, float], List[float]]]]
-
class
arcade.
Shape
[source]¶ Bases:
object
Primitive drawing shape. This can be part of a ShapeElementList so shapes can be drawn faster in batch.
-
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.
-
property
center_x
¶ Get the center x coordinate of the ShapeElementList.
-
property
center_y
¶ Get the center y coordinate of the ShapeElementList.
-
property
-
class
arcade.
Sound
(file_name: Union[str, pathlib.Path], streaming: bool = False)[source]¶ Bases:
object
This class represents a sound you can play.
-
__init__
(file_name: Union[str, pathlib.Path], streaming: bool = False)[source]¶
-
get_stream_position
(player: pyglet.media.player.Player) → float[source]¶ Return where we are in the stream. This will reset back to zero when it is done playing.
- Parameters
player (pyglet.media.Player) – Player returned from
play_sound()
.
-
get_volume
(player: pyglet.media.player.Player) → float[source]¶ Get the current volume.
- Parameters
player (pyglet.media.Player) – Player returned from
play_sound()
.- Returns
A float, 0 for volume off, 1 for full volume.
- Return type
-
is_complete
(player: pyglet.media.player.Player) → bool[source]¶ Return true if the sound is done playing.
-
is_playing
(player: pyglet.media.player.Player) → bool[source]¶ Return if the sound is currently playing or not
- Parameters
player (pyglet.media.Player) – Player returned from
play_sound()
.- Returns
A boolean,
True
if the sound is playing.- Return type
-
play
(volume: float = 1.0, pan: float = 0.0, loop: bool = False) → pyglet.media.player.Player[source]¶ Play the sound.
-
set_volume
(volume, player: pyglet.media.player.Player) → None[source]¶ Set the volume of a sound as it is playing.
- Parameters
volume (float) – Floating point volume. 0 is silent, 1 is full.
player (pyglet.media.Player) – Player returned from
play_sound()
.
-
-
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, flipped_horizontally: bool = False, flipped_vertically: bool = False, flipped_diagonally: bool = False, mirrored: bool = None, hit_box_algorithm: str = 'Simple', hit_box_detail: float = 4.5)[source]¶ Bases:
object
Class that represents a ‘sprite’ on-screen. Most games center around sprites. For examples on how to use this class, see: http://arcade.academy/examples/index.html#sprites
- 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. You probably don’t want to use this field. Instead, set points in the hit box.
- 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.
-
__init__
(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, flipped_horizontally: bool = False, flipped_vertically: bool = False, flipped_diagonally: bool = False, mirrored: bool = None, hit_box_algorithm: str = 'Simple', hit_box_detail: float = 4.5)[source]¶ Create a new sprite.
- Parameters
filename (str) – Filename of an image that represents the sprite.
scale (float) – Scale the image up or down. Scale of 1.0 is none.
image_x (float) – X offset to sprite within sprite sheet.
image_y (float) – Y offset to sprite within sprite sheet.
image_width (float) – Width of the sprite
image_height (float) – Height of the sprite
center_x (float) – Location of the sprite
center_y (float) – Location of the sprite
flipped_horizontally (bool) – Mirror the sprite image. Flip left/right across vertical axis.
flipped_vertically (bool) – Flip the image up/down across the horizontal axis.
flipped_diagonally (bool) – Transpose the image, flip it across the diagonal.
mirrored – Deprecated.
hit_box_algorithm (str) –
One of ‘None’, ‘Simple’ or ‘Detailed’. Defaults to ‘Simple’. Use ‘Simple’ for the
PhysicsEngineSimple
,PhysicsEnginePlatformer
and ‘Detailed’ for thePymunkPhysicsEngine
.hit_box_algorithm = “None”¶
hit_box_algorithm = “Simple”¶
hit_box_algorithm = “Detailed”¶
hit_box_detail (float) – Float, defaults to 4.5. Used with ‘Detailed’ to hit box
-
add_spatial_hashes
()[source]¶ Add spatial hashes for this sprite in all the sprite lists it is part of.
-
property
alpha
¶ Return the alpha associated with the sprite.
-
property
angle
¶ Get the angle of the sprite’s rotation.
-
append_texture
(texture: arcade.texture.Texture)[source]¶ Appends a new texture to the list of textures that can be applied to this sprite.
- Parameters
texture (arcade.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
- Parameters
sprite_list (SpriteList) – SpriteList to check against
- Returns
SpriteList of all overlapping Sprites from the original SpriteList
- Return type
-
collides_with_point
(point: Union[Tuple[float, float], List[float]]) → bool[source]¶ Check if point is within the current sprite.
- Parameters
point (Point) – Point to check.
- Returns
True if the point is contained within the sprite’s boundary.
- Return type
-
collides_with_sprite
(other: arcade.Sprite) → bool[source]¶ Will check if a sprite is overlapping (colliding) another Sprite.
-
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_hit_box
(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]] = (0, 0, 0), line_thickness: float = 1)[source]¶ Draw a sprite’s hit-box.
The ‘hit box’ drawing is cached, so if you change the color/line thickness later, it won’t take.
- Parameters
color – Color of box
line_thickness – How thick the box should be
-
forward
(speed: float = 1.0)[source]¶ Set a Sprite’s position to speed by its angle :param speed: speed factor
-
get_adjusted_hit_box
() → Sequence[Union[Tuple[float, float], List[float]]][source]¶ Get the points that make up the hit box for the rect that makes up the sprite, including rotation and scaling.
-
get_hit_box
() → Sequence[Union[Tuple[float, float], List[float]]][source]¶ Get a sprite’s hit box, unadjusted for translation, rotation, or scale.
-
get_points
() → Sequence[Union[Tuple[float, float], List[float]]][source]¶ Get the points that make up the hit box for the rect that makes up the sprite, including rotation and scaling.
-
property
height
¶ Get the height in pixels of the sprite.
-
property
hit_box
¶ Get a sprite’s hit box, unadjusted for translation, rotation, or scale.
-
property
left
¶ Return the x coordinate of the left-side of the sprite’s hit box.
-
on_update
(delta_time: float = 0.016666666666666666)[source]¶ Update the sprite. Similar to update, but also takes a delta-time.
-
property
points
¶ Get the points that make up the hit box for the rect that makes up the sprite, including rotation and scaling.
-
property
position
¶ Get the center x and y coordinates of the sprite.
- Returns:
(center_x, center_y)
-
pymunk_moved
(physics_engine, dx, dy, d_angle)[source]¶ Called by the pymunk physics engine if this sprite moves.
-
property
radians
¶ Converts the degrees representation of self.angle into radians. :return: float
-
register_physics_engine
(physics_engine)[source]¶ Called by the Pymunk physics engine when this sprite is added to that physics engine. Lets the sprite know about the engine and remove itself if it gets deleted.
-
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.
-
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.
-
property
right
¶ Return the x coordinate of the right-side of the sprite’s hit box.
-
property
scale
¶ Get the scale of the sprite.
-
set_hit_box
(points: Sequence[Union[Tuple[float, float], List[float]]])[source]¶ Set a sprite’s hit box. Hit box should be relative to a sprite’s center, and with a scale of 1.0. Points will be scaled with get_adjusted_hit_box.
-
set_points
(points: Sequence[Union[Tuple[float, float], List[float]]])[source]¶ Set a sprite’s hitbox
-
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.
-
strafe
(speed: float = 1.0)[source]¶ Set a sprites position perpendicular to its angle by speed :param speed: speed factor
-
property
texture
¶
-
property
texture_transform
¶
-
property
top
¶ Return the y coordinate of the top of the sprite.
-
turn_left
(theta: float = 90)[source]¶ Rotate the sprite left a certain number of degrees. :param theta: change in angle
-
turn_right
(theta: float = 90)[source]¶ Rotate the sprite right a certain number of degrees. :param theta: change in angle
-
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.
- Parameters
delta_time (float) – Time since last update.
-
property
width
¶ Get the width of the sprite.
-
class
arcade.
SpriteCircle
(radius: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], soft: bool = False)[source]¶ Bases:
arcade.Sprite
This sprite is just an elliptical sprite of one solid color. No need to use an image file.
-
class
arcade.
SpriteList
(use_spatial_hash=None, spatial_hash_cell_size=128, is_static=False)[source]¶ Bases:
object
Keep a list of sprites. Contains many optimizations around batch-drawing sprites and doing collision detection. For optimization reasons, use_spatial_hash and is_static are very important.
-
__init__
(use_spatial_hash=None, spatial_hash_cell_size=128, is_static=False)[source]¶ Initialize the sprite list
- Parameters
use_spatial_hash (bool) – If set to True, this will make moving a sprite in the SpriteList slower, but it will speed up collision detection with items in the SpriteList. Great for doing collision detection with static walls/platforms.
spatial_hash_cell_size (int) –
is_static (bool) – Speeds drawing if the sprites in the list do not move. Will result in buggy behavior if the sprites move when this is set to True.
-
append
(item: _SpriteType)[source]¶ Add a new sprite to the list.
- Parameters
item (Sprite) – Sprite to add to the list.
-
array_of_images
: Optional[List[Any]]¶
-
property
center
¶ Get the mean center coordinates of all sprites in the list.
-
draw
(**kwargs)[source]¶ Draw this list of sprites.
- Parameters
filter – Optional parameter to set OpenGL filter, such as gl.GL_NEAREST to avoid smoothing.
blend_function – Optional parameter to set the OpenGL blend function used for drawing the sprite list, such as ‘arcade.Window.ctx.BLEND_ADDITIVE’ or ‘arcade.Window.ctx.BLEND_DEFAULT’
-
draw_hit_boxes
(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]] = (0, 0, 0, 255), line_thickness: float = 1)[source]¶ Draw all the hit boxes in this list
-
extend
(items: Union[list, SpriteList])[source]¶ Extends the current list with the given list
- Parameters
items (list) – list of Sprites to add to the list
-
next_texture_id
= 0¶
-
on_update
(delta_time: float = 0.016666666666666666)[source]¶ Update the sprite. Similar to update, but also takes a delta-time.
-
property
percent_sprites_moved
¶ What percent of the sprites moved?
-
pop
(index: int = - 1) → arcade.Sprite[source]¶ Pop off the last sprite, or the given index, from the list
-
preload_textures
(texture_list: List)[source]¶ Preload a set of textures that will be used for sprites in this sprite list.
- Parameters
texture_list (array) – List of textures.
-
remove
(item: _SpriteType)[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_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]¶ Call the update_animation in every sprite in the sprite list.
-
update_color
(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_height
(sprite: arcade.Sprite)[source]¶ Called by the Sprite class to update the size/scale in this sprite. Necessary for batch drawing of items.
- Parameters
sprite (Sprite) – Sprite to update.
-
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_size
(sprite: arcade.Sprite)[source]¶ Called by the Sprite class to update the size/scale in this 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
-
update_width
(sprite: arcade.Sprite)[source]¶ Called by the Sprite class to update the size/scale in this sprite. Necessary for batch drawing of items.
- Parameters
sprite (Sprite) – Sprite to update.
-
property
use_spatial_hash
¶ Are we using a spatial hash?
-
-
class
arcade.
SpriteSolidColor
(width: int, height: int, color)[source]¶ Bases:
arcade.Sprite
This sprite is just a rectangular sprite of one solid color. No need to use an image file.
-
class
arcade.
Texture
(name: str, image: PIL.Image.Image = None, hit_box_algorithm: str = 'Simple', hit_box_detail: float = 4.5)[source]¶ Bases:
object
Class that represents a texture. Usually created by the
load_texture
orload_textures
commands.- Attributes:
- name
Unique name of the texture. Used by load_textures for caching. If you are manually creating a texture, you can just set this to whatever.
- image
A
PIL.Image.Image
object.- width
Width of the texture in pixels.
- height
Height of the texture in pixels.
-
__init__
(name: str, image: PIL.Image.Image = None, hit_box_algorithm: str = 'Simple', hit_box_detail: float = 4.5)[source]¶ Create a texture, given a PIL Image object.
- Parameters
name (str) – Name of texture. Used for caching, so must be unique for each texture.
image (PIL.Image.Image) – Image to use as a texture.
hit_box_algorithm (str) –
One of ‘None’, ‘Simple’ or ‘Detailed’. Defaults to ‘Simple’. Use ‘Simple’ for the
PhysicsEngineSimple
,PhysicsEnginePlatformer
and ‘Detailed’ for thePymunkPhysicsEngine
.hit_box_algorithm = “None”¶
hit_box_algorithm = “Simple”¶
hit_box_algorithm = “Detailed”¶
hit_box_detail (float) – Float, defaults to 4.5. Used with ‘Detailed’ to hit box
-
draw_scaled
(center_x: float, center_y: float, scale: float = 1.0, angle: float = 0, alpha: int = 255)[source]¶ Draw the texture.
-
draw_sized
(center_x: float, center_y: float, width: float, height: float, angle: float = 0, alpha: int = 255)[source]¶
-
draw_transformed
(left: float, bottom: float, width: float, height: float, angle: float = 0, alpha: int = 255, texture_transform: arcade.texture.Matrix3x3 = <arcade.texture.Matrix3x3 object>)[source]¶
-
property
height
¶ Height of the texture in pixels.
-
property
hit_box_points
¶
-
property
width
¶ Width of the texture in pixels.
-
arcade.
Vector
¶ The central part of internal API.
This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.
alias of Union[Tuple[float, float], List[float]]
-
class
arcade.
View
(window: arcade.Window = None)[source]¶ Bases:
object
Support different views/screens in a window.
-
on_key_press
(symbol: int, modifiers: int)[source]¶ Override this function to add key press functionality.
-
on_key_release
(_symbol: int, _modifiers: int)[source]¶ Override this function to add key release functionality.
-
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) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) pressed during this event. See Modifiers.
-
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.
- 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) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) pressed during this event. See Modifiers.
-
on_mouse_release
(x: float, y: float, button: int, modifiers: int)[source]¶ Override this function to add mouse button functionality.
-
-
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, gl_version: Tuple[int, int] = (3, 3), screen: pyglet.canvas.base.Screen = None, visible: bool = True)[source]¶ Bases:
pyglet.window.BaseWindow
The Window class forms the basis of most advanced games that use Arcade. It represents a window on the screen, and manages events.
-
__init__
(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, gl_version: Tuple[int, int] = (3, 3), screen: pyglet.canvas.base.Screen = None, visible: bool = True)[source]¶ Construct a new window
- Parameters
width (int) – Window width
height (int) – Window height
title (str) – Title (appears in title bar)
fullscreen (bool) – Should this be full screen?
resizable (bool) – Can the user resize the window?
update_rate (float) – How frequently to update the window.
antialiasing (bool) – Should OpenGL’s anti-aliasing be enabled?
gl_version (Tuple[int,int]) – What OpenGL version to request. This is
(3, 3)
by default and can be overridden when using more advanced OpenGL features.visible (bool) – Should the window be visible immediately
-
property
background_color
¶ Get or set the background color for this window.
- Type
Color
-
clear
()[source]¶ Clears the window with the configured background color set through
arcade.Window.background_color
.
-
property
ctx
¶ The OpenGL context for this window.
- Type
-
property
current_view
¶ This property returns the current view being shown. To set a different view, call the
arcade.Window.show_view()
method.- Return type
-
get_location
() → Tuple[int, int][source]¶ Return the X/Y coordinates of the window
- Returns
x, y of window location
-
get_viewport
() → Tuple[float, float, float, float][source]¶ Get the viewport. (What coordinates we can see.)
-
on_key_press
(symbol: int, modifiers: int)[source]¶ Override this function to add key press functionality.
-
on_key_release
(symbol: int, modifiers: int)[source]¶ Override this function to add key release functionality.
-
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) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) pressed during this event. See Modifiers.
-
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.
- 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) – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) pressed during this event. See Modifiers.
-
on_mouse_release
(x: float, y: float, button: int, modifiers: int)[source]¶ Override this function to add mouse button functionality.
-
on_resize
(width: float, height: float)[source]¶ Override this function to add custom code to be called any time the window is resized. The only responsibility here is to update the viewport.
-
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_fullscreen
(fullscreen=True, screen=None, mode=None, width=None, height=None)[source]¶ Set if we are full screen or not.
- Parameters
fullscreen (bool) –
screen – Which screen should we display on? See
get_screens()
mode –
width (int) –
height (int) –
-
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_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) –
-
show_view
(new_view: arcade.View)[source]¶ Select the view to show. Calling this function is the same as setting the
arcade.Window.current_view()
attribute.- Parameters
new_view (View) – View to show
-
test
(frames: int = 10)[source]¶ Used by unit test cases. Runs the event loop a few times and stops.
- Parameters
frames (int) –
-
-
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.
astar_calculate_path
(start_point: Union[Tuple[float, float], List[float]], end_point: Union[Tuple[float, float], List[float]], astar_barrier_list: arcade.paths.AStarBarrierList, diagonal_movement=True)[source]¶ - Parameters
start_point (Point) –
end_point (Point) –
astar_barrier_list (AStarBarrierList) –
diagonal_movement (bool) –
Returns: List
-
arcade.
calculate_hit_box_points_detailed
(image: <module 'PIL.Image' from 'c:\\users\\craven\\desktop\\webserver\\arcade\\venv38\\lib\\site-packages\\PIL\\Image.py'>, hit_box_detail: float = 4.5)[source]¶ Given an image, this returns points that make up a hit box around it. Attempts to trim out transparent pixels.
- Parameters
image (Image) – Image get hit box from.
hit_box_detail (int) – How detailed to make the hit box. There’s a trade-off in number of points vs. accuracy.
- Returns
List of points
-
arcade.
calculate_hit_box_points_simple
(image)[source]¶ Given an image, this returns points that make up a hit box around it. Attempts to trim out transparent pixels.
- Parameters
image (Image) –
- Returns
List of points
-
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.
- Return type
-
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.
- Return type
-
arcade.
cleanup_texture_cache
()[source]¶ This cleans up the cache of textures. Useful when running unit tests so that the next test starts clean.
-
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_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).
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
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.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
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.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
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.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
arcade.
create_isometric_grid_lines
(width, height, tile_width, tile_height, color, line_width)[source]¶
-
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.
-
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
andcreate_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
andcreate_line_loop
, just changing the OpenGL type for the line drawing.
-
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.
Internally, thick lines are created by two triangles.
- 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_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 center.
right (float) – The right of the near plane relative to the plane’s center.
top (float) – The top of the near plane relative to the plane’s center.
bottom (float) – The bottom of the near plane relative to the plane’s center.
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.
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.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
- 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.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
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.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
arcade.
create_rectangle_filled_with_colors
(point_list, color_list) → arcade.Shape[source]¶ This function creates one rectangle/quad using a vertex buffer object.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
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.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
- 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.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
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.
create_triangles_filled_with_colors
(point_list, color_list) → arcade.Shape[source]¶ This function creates multiple rectangle/quads using a vertex buffer object.
The function returns a Shape object that can be drawn with
my_shape.draw()
. Don’t create the shape in the draw method, create it in the setup method and then draw it inon_draw
.For even faster performance, add multiple shapes into a ShapeElementList and draw that list. This allows nearly unlimited shapes to be drawn just as fast as one.
-
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 = - 1)[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) – Number of triangle segments that make up this circle. Higher is better quality, but slower render time. The default value of -1 means arcade will try to calulate a reasonable amount of segments based on the size of the circle.
-
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 = - 1)[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) – Number of triangle segments that make up this circle. Higher is better quality, but slower render time. The default value of -1 means arcade will try to calulate a reasonable amount of segments based on the size of the circle.
-
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 = - 1)[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) – Number of triangle segments that make up this circle. Higher is better quality, but slower render time. The default value of -1 means arcade will try to calulate a reasonable amount of segments based on the size of the circle.
-
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 = - 1)[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 triangle segments that make up this circle. Higher is better quality, but slower render time. The default value of -1 means arcade will try to calculate a reasonable amount of segments based on the size of the circle.
-
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
- 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_lrwh_rectangle_textured
(bottom_left_x: float, bottom_left_y: float, width: float, height: float, texture: arcade.texture.Texture, angle: float = 0, alpha: int = 255)[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
-
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.
-
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.
- 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) – The color, specified in RGB or RGBA format.
-
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_scaled_texture_rectangle
(center_x: float, center_y: float, texture: arcade.texture.Texture, scale: float = 1.0, angle: float = 0, alpha: int = 255)[source]¶ Draw a textured rectangle on-screen.
- Parameters
center_x (float) – x coordinate of rectangle center.
center_y (float) – y coordinate of rectangle center.
texture (int) – identifier of texture returned from load_texture() call
scale (float) – scale of texture
angle (float) – rotation of the rectangle. Defaults to zero.
alpha (float) – Transparency of image. 0 is fully transparent, 255 (default) is visible
-
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) → arcade.Sprite[source]¶ Draws text to the screen.
Internally this works by creating an image, and using the Pillow library to draw the text to it. Then use that image to create a sprite. We cache the sprite (so we don’t have to recreate over and over, which is slow) and use it to draw text to the screen.
This implementation does not support bold/italic like the older Pyglet-based implementation of draw_text. However if you specify the ‘italic’ or ‘bold’ version of the font via the font name, you will get that font. Just the booleans do not work.
- Parameters
text (str) – Text to draw
start_x (float) – x coordinate of the lower-left point to start drawing text
start_y (float) – y coordinate of the lower-left point to start drawing text
color (Color) – Color of the text
font_size (float) – Size of the text
width (float) – Width of the text-box for the text to go into. Used with alignment.
align (str) – Align left, right, center
Tuple[str, ..]] font_name (Union[str,) – Font name, or list of font names in order of preference
bold (bool) – Bold the font (currently unsupported)
italic (bool) – Italicize the font (currently unsupported)
anchor_x (str) – Anchor the font location, defaults to ‘left’
anchor_y (str) – Anchor the font location, defaults to ‘baseline’
rotation (float) – Rotate the text
-
arcade.
draw_text_2
(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]¶ Draws text to the screen using pyglet’s label instead. Doesn’t work.
-
arcade.
draw_texture_rectangle
(center_x: float, center_y: float, width: float, height: float, texture: arcade.texture.Texture, angle: float = 0, alpha: int = 255)[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 texture
height (float) – height of texture
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
-
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.
-
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
-
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.
earclip
(polygon)[source]¶ Simple earclipping algorithm for a given polygon p. polygon is expected to be an array of 2-tuples of the cartesian points of the polygon For a polygon with n points it will return n-2 triangles. The triangles are returned as an array of 3-tuples where each item in the tuple is a 2-tuple of the cartesian point.
- Implementation Reference:
-
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_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
-
arcade.
get_display_size
(screen_id: int = 0) → Tuple[int, int][source]¶ Return the width and height of a monitor.
The size of the primary monitor is returned by default.
-
arcade.
get_distance
(x1: float, y1: float, x2: float, y2: float)[source]¶ Get the distance between two points.
-
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
-
arcade.
get_four_byte_color
(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]) → Union[Tuple[int, int, int, int], List[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_game_controllers
()[source]¶ Get a list of all the game controllers
- Returns
List of game controllers
-
arcade.
get_image
(x: int = 0, y: int = 0, width: int = None, height: int = None) → PIL.Image.Image[source]¶ Get an image from the screen.
- Parameters
- Returns
A Pillow Image
- Return type
You can save the image like:
image = get_image() image.save('screenshot.png', 'PNG')
-
arcade.
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
-
arcade.
get_pixel
(x: int, y: int) → Tuple[int, int, int][source]¶ Given an x, y, will return RGB color value of that point.
-
arcade.
get_points_for_thick_line
(start_x: float, start_y: float, end_x: float, end_y: float, line_width: float)[source]¶ Function used internally for Arcade. OpenGL draws triangles only, so a think line must be two triangles that make up a rectangle. This calculates those points.
-
arcade.
get_projection
()[source]¶ Returns the current projection matrix used by sprites and shapes in arcade.
This is a shortcut for
`window.ctx.projection_2d_matrix
.- Returns
Numpy array with projection.
-
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:
-
arcade.
get_scaling_factor
(window=None) → float[source]¶ Gets the scaling factor of the given Window. This is the ratio between the window and framebuffer size. If no window is supplied the currently active window will be used.
-
arcade.
get_screens
()[source]¶ Return a list of screens. So for a two-monitor setup, this should return a list of two screens. Can be used with arcade.Window to select which window we full-screen on.
- Returns
List of screens, one for each monitor.
- Return type
List
-
arcade.
get_sprites_at_exact_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.
- Return type
-
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.
- Return type
-
arcade.
get_text_image
(text: str, text_color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], font_size: float = 12, width: int = 0, align: str = 'left', valign: str = 'top', font_name: Union[str, Tuple[str, …]] = ('calibri', 'arial'), background_color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]] = None, height: int = 0)[source]¶
-
arcade.
get_tilemap_layer
(map_object: pytiled_parser.objects.TileMap, layer_path: str) → Optional[pytiled_parser.objects.Layer][source]¶ Given a TileMap and a layer path, this returns the TileLayer.
- Parameters
map_object (pytiled_parser.objects.TileMap) – The map read in by the read_tmx function.
layer_path (str) – A string to match the layer name. Case sensitive.
- Returns
A TileLayer, or None if no layer was found.
-
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
() → pyglet.window.BaseWindow[source]¶ Return a handle to the current window.
- Returns
Handle to the current window.
-
arcade.
has_line_of_sight
(point_1: Union[Tuple[float, float], List[float]], point_2: Union[Tuple[float, float], List[float]], walls: arcade.SpriteList, max_distance: int = - 1)[source]¶ Determine if we have line of sight between two points. Having a line of sight means, that you can connect both points with straight line without intersecting any obstacle. Thanks to the shapely efficiency and speedups boost, this method is very fast. It can easily test 10 000 lines_of_sight.
- Parameters
point_1 – tuple – coordinates of first position (x, y)
point_2 – tuple – coordinates of second position (x, y)
walls – list – Obstacle objects to check against
max_distance – int –
- Returns
tuple – (bool, 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
-
arcade.
lerp
(v1: float, v2: float, u: float) → float[source]¶ linearly interpolate between two values
-
arcade.
lerp_vec
(v1: Union[Tuple[float, float], List[float]], v2: Union[Tuple[float, float], List[float]], u: float) → Union[Tuple[float, float], List[float]][source]¶
-
arcade.
load_sound
(path: Union[str, pathlib.Path], streaming: bool = False) → Optional[arcade.Sound][source]¶ Load a sound.
- Parameters
path (Path) – Name of the sound file to load.
streaming (bool) – Boolean for determining if we stream the sound or load it all into memory. Set to
True
for long sounds to save memory,False
for short sounds to speed playback.
- Returns
Sound object which can be used by the
play_sound()
function.- Return type
-
arcade.
load_spritesheet
(file_name: Union[str, pathlib.Path], sprite_width: int, sprite_height: int, columns: int, count: int, margin: int = 0) → List[arcade.texture.Texture][source]¶ - Parameters
- Returns List
List of
Texture
objects.
-
arcade.
load_texture
(file_name: Union[str, pathlib.Path], x: float = 0, y: float = 0, width: float = 0, height: float = 0, flipped_horizontally: bool = False, flipped_vertically: bool = False, flipped_diagonally: bool = False, can_cache: bool = True, mirrored=None, hit_box_algorithm='Simple', hit_box_detail: float = 4.5) → arcade.texture.Texture[source]¶ Load an 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. Be careful with 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.
flipped_horizontally (bool) – Mirror the sprite image. Flip left/right across vertical axis.
flipped_vertically (bool) – Flip the image up/down across the horizontal axis.
flipped_diagonally (bool) – Transpose the image, flip it across the diagonal.
can_cache (bool) – If a texture has already been loaded, load_texture will return the same texture in order to save time. Sometimes this is not desirable, as resizing a cached texture will cause all other textures to resize with it. Setting can_cache to false will prevent this issue at the experience of additional resources.
mirrored (bool) – Deprecated.
hit_box_algorithm (str) –
One of ‘None’, ‘Simple’ or ‘Detailed’. Defaults to ‘Simple’. Use ‘Simple’ for the
PhysicsEngineSimple
,PhysicsEnginePlatformer
and ‘Detailed’ for thePymunkPhysicsEngine
.hit_box_algorithm = “None”¶
hit_box_algorithm = “Simple”¶
hit_box_algorithm = “Detailed”¶
hit_box_detail (float) – Float, defaults to 4.5. Used with ‘Detailed’ to hit box
- Returns
New
Texture
object.- Raises
ValueError
-
arcade.
load_texture_pair
(filename, hit_box_algorithm: str = 'Simple')[source]¶ Load a texture pair, with the second being a mirror image of the first. Useful when doing animations and the character can face left/right.
-
arcade.
load_textures
(file_name: Union[str, pathlib.Path], 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) → List[arcade.texture.Texture][source]¶ Load a set of textures from 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. Be careful with 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 (List) – 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.
- Returns
List of
Texture
’s.- Raises
ValueError
-
arcade.
make_burst_emitter
(center_xy: Union[Tuple[float, float], List[float]], filenames_and_textures: Sequence[Union[str, arcade.texture.Texture]], particle_count: int, particle_speed: float, particle_lifetime_min: float, particle_lifetime_max: float, particle_scale: float = 1.0, fade_particles: bool = True)[source]¶ Returns an emitter that emits all of its particles at once
-
arcade.
make_circle_texture
(diameter: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]]) → arcade.texture.Texture[source]¶ Return a Texture of a circle with the given diameter and color.
-
arcade.
make_interval_emitter
(center_xy: Union[Tuple[float, float], List[float]], filenames_and_textures: Sequence[Union[str, arcade.texture.Texture]], emit_interval: float, emit_duration: float, particle_speed: float, particle_lifetime_min: float, particle_lifetime_max: float, particle_scale: float = 1.0, fade_particles: bool = True)[source]¶ Returns an emitter that emits its particles at a constant rate for a given amount of time
-
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.Texture[source]¶ Return a
Texture
of a circle with the given diameter and color, fading out at its edges.- Parameters
- Returns
New
Texture
object.- Return type
-
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.Texture[source]¶ Return a
Texture
of a square with the given diameter and color, fading out at its edges.
-
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.
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.
-
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.
play_sound
(sound: arcade.Sound, volume: float = 1.0, pan: float = 0.0, looping: bool = False) → pyglet.media.player.Player[source]¶ Play a sound.
- Parameters
sound (Sound) – Sound loaded by
load_sound()
. Do NOT use a string here for the filename.volume (float) – Volume, from 0=quiet to 1=loud
pan (float) – Pan, from -1=left to 0=centered to 1=right
-
arcade.
process_layer
(map_object: pytiled_parser.objects.TileMap, layer_name: str, scaling: float = 1, base_directory: str = '', use_spatial_hash: Optional[bool] = None, hit_box_algorithm='Simple', hit_box_detail: float = 4.5) → 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.
use_spatial_hash – If all, or at least 75%, of the loaded tiles will not move between frames and you are using either the simple physics engine or platformer physics engine, set this to True to speed collision calculation. Leave False if using PyMunk, if all sprites are moving, or if no collision will be checked.
hit_box_algorithm (str) –
One of ‘None’, ‘Simple’ or ‘Detailed’. Defaults to ‘Simple’. Use ‘Simple’ for the
PhysicsEngineSimple
,PhysicsEnginePlatformer
and ‘Detailed’ for thePymunkPhysicsEngine
.hit_box_algorithm = “None”¶
hit_box_algorithm = “Simple”¶
hit_box_algorithm = “Detailed”¶
hit_box_detail (float) – Float, defaults to 4.5. Used with ‘Detailed’ to hit box
- Returns
A SpriteList.
-
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.
rand_in_circle
(center: Union[Tuple[float, float], List[float]], radius: float)[source]¶ Generate a point in a circle, or can think of it as a vector pointing a random direction with a random magnitude <= radius Reference: http://stackoverflow.com/a/30564123 Note: This algorithm returns a higher concentration of points around the center of the circle
-
arcade.
rand_in_rect
(bottom_left: Union[Tuple[float, float], List[float]], width: float, height: float) → Union[Tuple[float, float], List[float]][source]¶
-
arcade.
rand_on_circle
(center: Union[Tuple[float, float], List[float]], radius: float) → Union[Tuple[float, float], List[float]][source]¶ Note: by passing a random value in for float, you can achieve what rand_in_circle() does
-
arcade.
rand_on_line
(pos1: Union[Tuple[float, float], List[float]], pos2: Union[Tuple[float, float], List[float]]) → Union[Tuple[float, float], List[float]][source]¶
-
arcade.
rand_vec_magnitude
(angle: float, lo_magnitude: float, hi_magnitude: float) → Union[Tuple[float, float], List[float]][source]¶
-
arcade.
rand_vec_spread_deg
(angle: float, half_angle_spread: float, length: float) → Union[Tuple[float, float], List[float]][source]¶
-
arcade.
read_tmx
(tmx_file: Union[str, pathlib.Path]) → 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
-
arcade.
render_text
(text: arcade.CreateText, start_x: float, start_y: float)[source]¶ Deprecated. Two step text drawing for backwards compatibility.
-
arcade.
rotate_point
(x: float, y: float, cx: float, cy: float, angle_degrees: float) → List[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_degrees – Angle, in degrees, to rotate
- Returns
Return rotated (x, y) pair
- Return type
-
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. The function/callable needs to take a delta time argument similar toon_update
. This is a float representing the number of seconds since the method was scheduled or called.A function can be scheduled multiple times, but this is not recommended.
Warning
Scheduled functions should always be unscheduled using
arcade.unschedule()
. Having lingering scheduled functions will lead to crashes.Example:
def some_action(delta_time): print(delta_time) # Call the function every second arcade.schedule(some_action, 1) # Unschedule
- Parameters
function_pointer (Callable) – Pointer to the function to be called.
interval (Number) – Interval to call the function (float or integer)
-
arcade.
screen_to_isometric_grid
(screen_x, screen_y, width, height, tile_width, tile_height)[source]¶
-
arcade.
set_background_color
(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])[source]¶ Specifies the background color of the window. This value will persist for every future screen clears until changed.
- 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.
Note: Window.on_resize will call set_viewport by default. If you set your own custom viewport, you may need to over-ride this method.
For more advanced users: This functions sets the orthogonal projection used by shapes and sprites using the values passed in. it also updates the viewport to match the current screen resolution.
`window.ctx.projection_2d
andwindow.ctx.viewport`
can be used to set viewport and projection separately.- 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.
stop_sound
(player: pyglet.media.player.Player)[source]¶ Stop a sound that is currently playing.
- Parameters
player (pyglet.media.Player) – Player returned from
play_sound()
.
-
arcade.
trim_image
(image: PIL.Image.Image) → PIL.Image.Image[source]¶ Crops the extra whitespace out of an image.
- Returns
New
PIL.Image.Image
object.
-
arcade.
unschedule
(function_pointer: Callable)[source]¶ Unschedule a function being automatically called.
Example:
def some_action(delta_time): print(delta_time) arcade.schedule(some_action, 1) arcade.unschedule(some_action)
- Parameters
function_pointer (Callable) – Pointer to the function to be unscheduled.