BaseGame class

This is a more complete and opinionated implementation of Game.

It still needs to be subclasses to add your game logic, but the update, render and resize methods have default implementations. This is the recommended structure to use for most games. It is based on the Component system.

Mixed in types




builder WidgetBuilder
final, inherited
camera Position
Camera position; every non-HUD component is translated so that the camera position is the top-left corner of the screen.
read / write
components OrderedSet<Component>
The list of components to be updated and rendered by the base game.
read / write
hashCode int
The hash code for this object. [...]
read-only, inherited
pauseEngineFn VoidCallback
read / write, inherited
resumeEngineFn VoidCallback
read / write, inherited
runOnCreation bool
Flag to tell the game loop if it should start running upon creation
read / write, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
size Size
Current screen size, updated every resize via the resize method hook
read / write
widget Widget
Returns the game widget. Put this in your structure to start rendering and updating the game. You can add it directly to the runApp method or inside your widget structure (if you use vanilla screens and widgets).
read-only, inherited


add(Component c) → void
Adds a new component to the components list. [...]
addLater(Component c) → void
Registers a component to be added on the components on the next tick. [...]
backgroundColor() Color
Returns the game background color. By default it will return a black color. It cannot be changed at runtime, because the game widget does not get rebuild when this value changes.
currentTime() double
Returns the current time in seconds with microseconds precision. [...]
debugMode() bool
Returns whether this Game is in debug mode or not. [...]
fps([int average = 1]) double
Returns the FPS based on the frame times from onTimingsCallback.
lifecycleStateChange(AppLifecycleState state) → void
This is the lifecycle state change hook; every time the game is resumed, paused or suspended, this is called. [...]
markToRemove(Component c) → void
Marks a component to be removed from the components list on the next game loop cycle
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
onAttach() → void
@mustCallSuper, inherited
onDetach() → void
@mustCallSuper, inherited
onTimingsCallback(List<FrameTiming> timings) → void
Use for caluclating the FPS.
pauseEngine() → void
Pauses the engine game loop execution
preAdd(Component c) → void
This method is called for every component added, both via add and addLater methods. [...]
recordDt(double dt) → void
Used for debugging
@Deprecated('Gets called for backward compatibility, will be removed in v1'), inherited
recordFps() bool
Returns whether this Game is should record fps or not. [...]
render(Canvas canvas) → void
This implementation of render basically calls renderComponent for every component, making sure the canvas is reset for each one. [...]
@mustCallSuper, override
renderComponent(Canvas canvas, Component c) → void
This renders a single component obeying BaseGame rules. [...]
resize(Size size) → void
This implementation of resize passes the resize call along to every component in the list, enabling each one to make their decisions as how to handle the resize. [...]
@mustCallSuper, override
resumeEngine() → void
Resumes the engine game loop execution
toString() String
A string representation of this object. [...]
update(double t) → void
This implementation of update updates every component in the list. [...]
@mustCallSuper, override


operator ==(Object other) bool
The equality operator. [...]