Sprite

Make creating games with 2D sprites more easy and clean.

class sprite.Sprite(x=0, y=0, image_name=None)

Class that represents a moveable 2D image.

Parameters:
  • x (float) – The x-coordinate, in pixels, of the center of the sprite.
  • y (float) – The y-coordinate, in pixels, of the center of the sprite.
  • image_name (str) – The file name of the image to draw when drawing the sprite. The image must be a gif file.

Attributes

Sprite.x

The x-coordinate, in pixels, of the center of this sprite.

Sprite.y

The y-coordinate, in pixels, of the center of this sprite.

Sprite.image_name

The name of the image to draw, when drawing this sprite.

Read-only Attributes

Sprite.width

The width of this Sprite, when drawn.

Sprite.height

The height of this Sprite, when drawn.

Methods

Sprite.uncollide(other_sprite)

Moves this Sprite so that it does not overlap with another Sprite.

Parameters:other_sprite (Sprite) – Another Sprite object.

Moves this sprite the minimum amount so that it is not overlapping with other_sprite. If there is no overlap, it does nothing.

Sprite.collides(other_sprite)

Returns whether this Sprite is colliding with another Sprite.

Parameters:other_sprite (Sprite) – Another Sprite object.
Returns:(bool) – Returns True if this sprite is overlapping with other_sprite and False otherwise.

Table Of Contents

Previous topic

Graphics

This Page