- class arcade.AnimatedTimeBasedSprite(filename: Optional[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)#
Sprite for platformer games that supports animations. These can be automatically created by the Tiled Map Editor.
- class arcade.AnimatedWalkingSprite(scale: float = 1, image_x: float = 0, image_y: float = 0, center_x: float = 0, center_y: float = 0)#
Deprecated 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.
It is highly recommended you create your own version of this class rather than try to use this pre-packaged one.
For an example, see this section of the platformer tutorial: Step 12 - Add Character Animations, and Better Keyboard Control.
- class arcade.PyMunk#
Object used to hold pymunk info for a sprite.
- class arcade.Sprite(filename: Optional[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, hit_box_algorithm: Optional[str] = 'Simple', hit_box_detail: float = 4.5, texture: Optional[arcade.texture.Texture] = None, angle: float = 0)#
Class that represents a ‘sprite’ on-screen. Most games center around sprites. For examples on how to use this class, see: https://api.arcade.academy/en/latest/examples/index.html#sprites
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.
hit_box_algorithm (str) – One of None, ‘None’, ‘Simple’ or ‘Detailed’. Defaults to ‘Simple’. Use ‘Simple’ for the
PhysicsEnginePlatformerand ‘Detailed’ for the
texture (Texture) – Specify the texture directly.
angle (float) – The initial rotation of the sprite in degrees
This will ignore all hit box and image size arguments.
hit_box_detail (float) – Float, defaults to 4.5. Used with ‘Detailed’ to hit box
Transparency of sprite. 0 is invisible, 255 is opaque.
Rotation angle in degrees. Sprites rotate counter-clock-wise.
Rotation angle in radians. Sprites rotate counter-clock-wise.
Set/query the sprite location by using the bottom coordinate. This will be the ‘y’ of the bottom of the sprite.
Used in movement. Left boundary of moving sprite.
Used in movement. Right boundary of moving sprite.
Used in movement. Top boundary of moving sprite.
Used in movement. Bottom boundary of moving sprite.
X location of the center of the sprite
Y location of the center of the sprite
Movement vector, in the x direction.
Movement vector, in the y direction.
Change in rotation.
Color tint the sprite
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.
Index of current texture being used.
Unique identifier for the sprite. Useful when debugging.
Height of the sprite.
Force being applied to the sprite. Useful when used with Pymunk for physics.
Points, in relation to the center of the sprite, that are used for collision detection. Arcade defaults to creating a hit box via the ‘simple’ hit box algorithm that encompass the image. If you are creating a ramp or making better hit-boxes, you can custom-set these.
Set/query the sprite location by using the left coordinate. This will be the ‘x’ of the left of the sprite.
A list with the (x, y) of where the sprite is.
Set/query the sprite location by using the right coordinate. This will be the ‘y=x’ of the right of the sprite.
List of all the sprite lists this sprite is part of.
arcade.Textureclass with the current texture. Setting a new texture does not update the hit box of the sprite. This can be done with
my_sprite.hit_box = my_sprite.texture.hit_box_points. New textures will be centered on the current center_x/center_y.
List of textures associated with this sprite.
Set/query the sprite location by using the top coordinate. This will be the ‘y’ of the top of the sprite.
Scale the image up or down. Scale of 1.0 is original size, 0.5 is 1/2 height and width.
Change in x, y expressed as a list. (0, 0) would be not moving.
Width of the sprite
It is common to over-ride the update method and provide mechanics on movement or other sprite updates.
Add spatial hashes for this sprite in all the sprite lists it is part of.
- append_texture(texture: arcade.texture.Texture)#
Appends a new texture to the list of textures that can be applied to this sprite.
texture (arcade.Texture) – Texture to add to the list of available textures
Return the y coordinate of the bottom of the sprite.
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 #
Check if current sprite is overlapping with any other sprite in a list
- collides_with_point(point: Union[Tuple[float, float], List[float]]) bool #
Check if point is within the current sprite.
point (Point) – Point to check.
True if the point is contained within the sprite’s boundary.
- Return type
- collides_with_sprite(other: arcade.sprite.Sprite) bool #
Will check if a sprite is overlapping (colliding) another Sprite.
- property collision_radius: float#
Get the collision radius.
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: Union[Tuple[int, int, int], List[int]]#
Return the RGB color associated with the sprite.
- draw(*, filter=None, pixelated=None, blend_function=None)#
Draw the sprite.
filter – Optional parameter to set OpenGL filter, such as gl.GL_NEAREST to avoid smoothing.
Truefor pixelated and
Falsefor smooth interpolation. Shortcut for setting filter=GL_NEAREST.
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_box(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]] = (0, 0, 0), line_thickness: float = 1)#
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.
color – Color of box
line_thickness – How thick the box should be
- face_point(point: Union[Tuple[float, float], List[float]])#
Face the sprite towards a point. Assumes sprite image is facing upwards.
point (Point) – Point to face towards.
- forward(speed: float = 1.0)#
Adjusts a Sprite’s movement vector forward. This method does not actually move the sprite, just takes the current change_x/change_y and adjusts it by the speed given.
speed – speed factor
- get_adjusted_hit_box() Sequence[Union[Tuple[float, float], List[float]]] #
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]]] #
Use the hit_box property to get or set a sprite’s hit box. Hit boxes are specified assuming the sprite’s center is at (0, 0). Specify hit boxes like:
mySprite.hit_box = [[-10, -10], [10, -10], [10, 10]]
Specify a hit box unadjusted for translation, rotation, or scale. You can get an adjusted hit box with
Alias of remove_from_sprite_lists
- on_update(delta_time: float = 0.016666666666666666)#
Update the sprite. Similar to update, but also takes a delta-time.
- property position: Union[Tuple[float, float], List[float]]#
Get the center x and y coordinates of the sprite.
- property properties: Dict[str, Any]#
Get or set custom sprite properties.
- Return type
- property pymunk: arcade.sprite.PyMunk#
Get or set the Pymunk property objects. This is used by the pymunk physics engine.
- pymunk_moved(physics_engine, dx, dy, d_angle)#
Called by the pymunk physics engine if this sprite moves.
- property radians: float#
Converts the degrees representation of self.angle into radians. :return: float
Register a physics engine on the sprite. This is only needed if you actually need a reference to your physics engine in the sprite itself. It has no other purposes.
The registered physics engines can be accessed through the
It can for example be the pymunk physics engine or a custom one you made.
- register_sprite_list(new_list: SpriteList)#
Register this sprite as belonging to a list. We will automatically remove ourselves from the the list when kill() is called.
Remove the sprite from all sprite lists.
- rescale_relative_to_point(point: Union[Tuple[float, float], List[float]], factor: float) None #
Rescale the sprite relative to a different point than its center.
- reverse(speed: float = 1.0)#
Adjusts a Sprite’s movement vector backwards. This method does not actually move the sprite, just takes the current change_x/change_y and adjusts it by the speed given.
speed – speed factor
- set_hit_box(points: Sequence[Union[Tuple[float, float], List[float]]])#
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_position(center_x: float, center_y: float)#
Set a sprite’s position
- set_texture(texture_no: int)#
Sets texture by texture id. Should be renamed because it takes a number rather than a texture, but keeping this for backwards compatibility.
Stop the Sprite’s motion.
- strafe(speed: float = 1.0)#
Adjusts a Sprite’s movement vector sideways. This method does not actually move the sprite, just takes the current change_x/change_y and adjusts it by the speed given.
speed – speed factor
- turn_left(theta: float = 90.0)#
Rotate the sprite left by the passed number of degrees.
theta – change in angle, in degrees
- turn_right(theta: float = 90.0)#
Rotate the sprite right by the passed number of degrees.
theta – change in angle, in degrees
Update the sprite.
- update_animation(delta_time: float = 0.016666666666666666)#
Override this to add code that will change what image is shown, so the sprite can be animated.
delta_time (float) – Time since last update.
- property visible: bool#
Get or set the visibility of this sprite. This is a shortcut for changing the alpha value of a sprite to 0 or 255:
# Make the sprite invisible sprite.visible = False # Change back to visible sprite.visible = True # Toggle visible sprite.visible = not sprite.visible
- Return type
- class arcade.SpriteCircle(radius: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]], soft: bool = False)#
This sprite is just an elliptical sprite of one solid color. No need to use an image file.
- class arcade.SpriteSolidColor(width: int, height: int, color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]])#
This sprite is just a rectangular sprite of one solid color. No need to use an image file.
Given an animated gif, return a AnimatedTimeBasedSprite.
Support for transparency in animated gifs in Python is lacking. There are a lot of older animated gifs that are saved weird. The end result is that the often the first frame of an animated gif is the only frame that we correctly get the transparency on. Until the Pillow library better handles this, loading animated gifs will be pretty buggy.