Engine

Engine

class serge.engine.Engine(width=640, height=480, title='Serge', backcolour=(0, 0, 0), icon=None, fullscreen=False)[source]

Bases: serge.common.Loggable, serge.serialize.Serializable, serge.common.EventAware

The main Serge engine

The engine manages a set of worlds and allows a single Worlds, the current world, to be automatically updated on a certain time frequency.

addWorld(world)[source]

Add a world to the engine

Parameters:world – the world instance to add
attachBuilder(builder)[source]

Attach a builder

clearWorlds()[source]

Clear all the worlds

detachBuilder()[source]

Detach the builder

getCurrentWorld()[source]

Return the currently selected world

getKeyboard()[source]

Return the keyboard

getMouse()[source]

Return the mouse

getProfiler()[source]

Return the current profiler

getRenderer()[source]

Return the renderer

getSprites()[source]

Return the sprite registry

getStats()[source]

Return the stats for the engine

getTimeSinceStart()[source]

Return the clock time since the engine was started

getWorld(name)[source]

Return the named world

Parameters:name – the name of the world to return
getWorlds()[source]

Return all the worlds

goBackToPreviousWorld(obj=None, arg=None)[source]

Return to the world we were in before this one

The arguments are never used and are just here to allow you to use this method as an event callback.

init()[source]

Initialise ourself

processEvents()[source]

Process all the events for the current world

profilingOn()[source]

Turn the profiling on

removeWorld(world)[source]

Remove a world from the engine

Parameters:world – the world instance to remove
removeWorldNamed(name)[source]

Remove a world with a given name

Parameters:name – the name of the world to remove
run(fps, endat=None)[source]

Run the updates at the specified frames per second until the optional endtime

Parameters:
  • fps – the target frames per second (integer)
  • endat – a time to stop the engine at (long), eg time.time()+60 to run for a minute
runAsync(fps, endat=None)[source]

Run the engine asynchronously

Parameters:
  • fps – the target frames per second (integer)
  • endat – a time to stop the engine at (long), eg time.time()+60 to run for a minute
save(filename)[source]

Store the engine state in a file suitable for loading again in the furture

Parameters:filename – the name of the file to save into
setCurrentWorld(world)[source]

Set the current world

Parameters:world – the world to set as the current world
setCurrentWorldByName(name)[source]

Set the current world to the one with the given name

Parameters:name – the name of the world to set as the current world
stop(process_events=True)[source]

Stop the engine running

updateWorld(interval)[source]

Update the current world

EngineStats

class serge.engine.EngineStats[source]

Statistic for the engine

afterRender()[source]

Record that we are after a rendering cycle

beforeRender()[source]

Record we are before a rendering cycle

recordFrame()[source]

Record a frame