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.

Inheritance
Mixed in types
Implementers

Constructors

BaseGame()

Properties

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

Methods

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.
inherited
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 average FPS for the last average measures. [...]
inherited
lifecycleStateChange(AppLifecycleState state) → void
This is the lifecycle state change hook; every time the game is resumed, paused or suspended, this is called. [...]
inherited
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. [...]
inherited
onAttach() → void
@mustCallSuper, inherited
onDetach() → void
@mustCallSuper, inherited
pauseEngine() → void
Pauses the engine game loop execution
inherited
preAdd(Component c) → void
This method is called for every component added, both via add and addLater methods. [...]
recordDt(double dt) → void
This is a hook that comes from the RenderBox to allow recording of render times and statistics.
inherited
recordFps() bool
Returns whether this Game is should record fps or not [...]
override
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
inherited
toString() String
Returns a string representation of this object.
inherited
update(double t) → void
This implementation of update updates every component in the list. [...]
@mustCallSuper, override

Operators

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