Visual

Sprites

serge.visual.Sprites

Registry of all sprites (is a Store)

Fonts

serge.visual.Fonts

Registry of all fonts (is a FontStore)

Drawing

class serge.visual.Drawing[source]

Bases: object

Represents something to draw on the screen

flipHorizontal()[source]

Flip the drawing horizontally

flipVertical()[source]

Flip the drawing vertically

getAngle()[source]

Return the current angle

getCopy()[source]

Return a copy

renderTo()[source]

Render to a surface

rotateBy(angle)[source]

Rotate by a certain amount

scaleBy(factor)[source]

Scale the image by a factor

setAlpha(alpha)[source]

Set the overall alpha

setAngle(angle)[source]

Set the rotation to a certain angle

setHorizontalFlip(flip)[source]

Set the horizontal flip state

setScale(scale)[source]

Set the scaling to a certain factor

setSize(width, height)[source]

Set the size of the drawing directly

setVerticalFlip(flip)[source]

Set the vertical flip state

SurfaceDrawing

class serge.visual.SurfaceDrawing(width, height, pixel_format=65536)[source]

Bases: serge.visual.Drawing

A visual object that renders to a surface.

You can create an instance of this class and then write to its surface or use this as a base class for your own class that will write the surface.

clearSurface()[source]

Clear the surface

getSurface()[source]

Return our surface

renderTo()[source]

Render to a surface

scaleBy(factor)[source]

Scale the image by a factor

setAngle(angle)[source]

Change the angle - returning the amount by which the sprite has shifted

setSize(width, height)[source]

Set the size of the drawing directly

setSurface(surface)[source]

Update our surface

Sprite

class serge.visual.Sprite[source]

Bases: serge.visual.Drawing

An object that gets drawn on the screen

flipHorizontal()[source]

Flip the drawing horizontally

flipVertical()[source]

Flip the drawing vertically

getCell()[source]

Return the current cell number

getCopy()[source]

Return a copy of this sprite

getNumberOfCells()[source]

Return the number of animation cells

getSurface()[source]

Return the current surface

renderTo()[source]

Render to a surface

resetAnimation(running)[source]

Reset the animation to the beginning

scaleBy(factor)[source]

Scale the image by a factor

setAlpha(alpha)[source]

Set the overall alpha

setAngle(angle)[source]

Change the angle - returning the amount by which the sprite has shifted

setCell(number)[source]

Set the current cell number

setCells()[source]

Create the cells for the animation of this sprite

setImage()[source]

Set the image of this sprite

setSize(width, height)[source]

Set the size of the drawing directly

FontStore

class serge.visual.FontStore[source]

Bases: serge.registry.GeneralStore

A store for fonts

clearItems()[source]

Clear the items

Leaves the DEFAULT item in there if it is there.

getFont(name, size)[source]

Return a font

This method implements a caching scheme. There seem to be problems on OSX repeatedly creating fonts and so we are caching here. This doesn’t seem to be needed on other platforms but we use it anyway as it should give a slight performance bonus.

registerItem(name, path)[source]

Register a font

Store

class serge.visual.Store[source]

Bases: serge.registry.GeneralStore

Stores sprites

registerFromFiles(name, path, number, framerate=0, running=False, rectangular=True, angle=0.0, zoom=1.0, start=1, loop=True, one_direction=False, convert_alpha=False)[source]

Register a multi cell sprite from a number of files

The path should be a string with a single numerical substitution. We will pass the numbers 1..number to this substitution to find the names of the files.

registerItemsFromPattern(pattern, prefix='', w=1, h=1, framerate=0, running=False, rectangular=True, angle=0.0, zoom=1.0, loop=True, one_direction=False, convert_alpha=False)[source]

Register all items matching a certain regular expression

The items will be registered as the filename with the extension dropped off. You can optionally specify a prefix to be used to put in front of the registered name.

registerMultipleItems(names, path, w, h=1, rectangular=True, angle=0.0, zoom=1.0, one_direction=False, convert_alpha=False)[source]

Register a number of sprites from a single image

The image must be a horizontal row of sprites and you must provide a list of names the same size as the row of sprites. Each other sprites will be created.

Text

class serge.visual.Text(text, colour, font_name='DEFAULT', font_size=12, justify='center', fixed_char_width=None)[source]

Bases: serge.visual.Drawing

Some text to display

convertAlpha(color_key=(127, 127, 127))[source]

Convert this text to an surface alpha

renderTo()[source]

Render to a surface

scaleBy(scale)[source]

Scale our sprite by a certain certain amount

setAlpha(alpha)[source]

Set our alpha

setAngle(angle)[source]

Rotate our sprite by a certain angle

setColour(colour)[source]

Set the colour

setFontSize(font_size)[source]

Set our font size

setJustify(justify)[source]

Set the justification

setText(text)[source]

Set our text