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
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. [...]
lifecycleStateChange(AppLifecycleState state) → void
This is the lifecycle state change hook; every time the game is resumed, paused or suspended, this is called. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
onAttach() → void
inherited
onDetach() → void
inherited
onTap() → void
inherited
onTapCancel() → void
override
onTapDown(TapDownDetails details) → void
override
onTapUp(TapUpDetails details) → void
override
preAdd(Component c) → void
This method is called for every component added, both via add and addLater methods. [...]
render(Canvas canvas) → void
This implementation of render basically calls renderComponent for every component, making sure the canvas is reset for each one. [...]
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
toString() String
A string representation of this object. [...]
inherited
update(double t) → void
This implementation of update updates every component in the list. [...]
override

Operators

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