Class GTile

This class is a variation on GImage for drawing an image file. However, while GImage resizes the image to fit the width and height, this image will tile it. Tiling means repeating the image over and over to fill the available space. So if the image is 64 by 64 pixels, and the GTile objects is 128 by 256 pixels, it will repeat the image twice horizontally and four times vertically. This is useful for drawing background terrain like grass, water, or roads.

Because this class does not scale the image, both width and height are required attributes. If you do not specify them when you construct the object, this will cause an error.

Constructor

class game2d.gtile.GTile(**keywords)

An class representing a tiles image

Normally, GImage objects scale the image to fit within the given width and height. A tileable image never scales implicitly (though you can scale explicitly with the scale attribute). Instead it repeats the image to fill in all of the remaining space. This is ideal for terrain and other background features

Creates a new tielable image.

To use the constructor for this class, you should provide it with a list of keyword arguments that initialize various attributes. For example, to load the image water.png, use the constructor:

GTile(x=0,y=0,width=10,height=10,source='water.png')

This class supports the all same keywords as GImage. However, the attributes width and height are required (so that the object knows how much space to fill). Leaving out these values will cause a ValueError.

Parameters:

keywords (keys are attribute names, including 'width' and 'height') – dictionary of keyword arguments

Attributes

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

GTile.rows

The number of times this image appears vertically

This value is a float, as sometimes only a portion of the image is drawn.

GTile.columns

The number of times this image appears horizontally

This value is a float, as sometimes only a portion of the image is drawn.

Methods

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

Return to top level