Class GSprite

The class provides support simple sprite sheet animation. The sprite sheet is given by a JPEG, PNG, or GIF file whose name is stored in the attribute source. Sprite sheets should be stored in the Images directory so that Kivy can find them without the complete path name.

A sprite sheet, or filmstrip, is a single image file that contains animation frames of equal size. The animations frames are arranged in a rectangular grid. When you make a GSprite object, it reads in the frames left-to-right, top-to-bottom. At any time, you can change the frame attribute to control which frame is shown on screen.

Beyond the support for animation frames, this class is identical to GImage.

Constructor

class game2d.gsprite.GSprite(**keywords)

An class representing a filmstrip for animating.

The image is given by a JPEG, PNG, or GIF file whose name is stored in the attribute source. Image files should be stored in the Images directory so that Kivy can find them without the complete path name.

The image is broken up in to a sequence of frames. These frames are arranged in a 2d grid and are arranged left-to-right, top-to-bottom. By specifying the frame, you can control what image is displayed inside of this rectangle.

If the attributes width and height do not agree with the actual size of a single frame, the image is scaled to fit.Furthermore, if you define fillcolor, this object will tint your image by the given color.`

If the image supports transparency, then this object can be used to represent irregular shapes. However, the contains() method still treats this shape as a rectangle.

Attributes

This class has all of the attributes of GImage. In addition, it has the following new attributes.

GSprite.frame

The current animation frame of this filmstrip

invariant. Value is an int 0..count-1.

GSprite.format

The grid size of this sprite.

The format is specified as (rows, columns). It will divide the image up into equal portions to match this. All images will have the same width, and the same height, but the width can be different from the height.

Invariant: Value is a 2-element tuple of ints > 0

GSprite.count

The number of frames in this filmstrip

invariant. Value is an int > 0.

Methods

This class does not have any methods beyond those defined in GObject.

Return to top level