Game class abstract mixin

This gives access to a low-level game API, to not build everything from a low level FlameGame should be used.

You can either extend this class, or add it as a mixin.

Methods update and render need to be implemented in order to connect your class with the internal game loop.

Implementers
Available Extensions

Constructors

Game()

Properties

assets AssetsCache
The cache of all (non-image) assets loaded into the game. This defaults to the global Flame.assets cache, but you can replace this with another instance if needed.
getter/setter pair
buildContext BuildContext?
Currently attached build context. Can be null if not attached.
no setter
canvasSize Vector2
no setter
gameStateListeners List<VoidCallback>
final
gestureDetectors → GestureDetectorBuilder
Used internally by various mixins that need to use gesture detection functionality in Flutter.
latefinal
hashCode int
The hash code for this object.
no setterinherited
hasLayout bool
Indicates if this game instance is connected to a GameWidget that is live in the flutter widget tree. Once this is true, the game is ready to have its size used or in the case of a FlameGame, to receive components.
no setter
images Images
The cache of all images loaded into the game. This defaults to the global Flame.images cache, but you can replace it with a new cache instance if needed.
getter/setter pair
isAttached bool
Whether the game widget was attached to the Flutter tree.
no setter
mouseCursor MouseCursor
Used to change the mouse cursor of the GameWidget running this game. Setting the value to null will make the GameWidget defer the choice of the cursor to the closest region available on the tree.
getter/setter pair
mouseDetector ↔ (void Function(PointerHoverEvent event)?)
Set by the PointerMoveDispatcher to receive mouse events from the game widget.
getter/setter pair
overlays → OverlayManager
A property that stores an OverlayManager
latefinal
paused bool
Returns is the engine if currently paused or running
getter/setter pair
renderBox → GameRenderBox
Just a reference back to the render box that is kept up to date by the engine.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size Vector2
Current game viewport size, updated every resize via the onGameResize method hook.
no setter

Methods

addGameStateListener(VoidCallback callback) → void
assertHasLayout() → void
attach(PipelineOwner owner, GameRenderBox gameRenderBox) → void
Marks game as attached to any Flutter widget tree.
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.
convertGlobalToLocalCoordinate(Vector2 point) Vector2
Converts a global coordinate (i.e. w.r.t. the app itself) to a local coordinate (i.e. w.r.t. he game widget). If the widget occupies the whole app ("full screen" games), or is not attached to Flutter, this operation is the identity.
convertLocalToGlobalCoordinate(Vector2 point) Vector2
Converts a local coordinate (i.e. w.r.t. the game widget) to a global coordinate (i.e. w.r.t. the app itself). If the widget occupies the whole app ("full screen" games), or is not attached to Flutter, this operation is the identity.
detach() → void
Marks game as no longer attached to any Flutter widget tree.
finalizeRemoval() → void
lifecycleStateChange(AppLifecycleState state) → void
This is the lifecycle state change hook; every time the game is resumed, paused or suspended, this is called.
load() FutureOr<void>
loadSprite(String path, {Vector2? srcSize, Vector2? srcPosition}) Future<Sprite>
Utility method to load and cache the image for a sprite based on its options.
loadSpriteAnimation(String path, SpriteAnimationData data) Future<SpriteAnimation>
Utility method to load and cache the image for a sprite animation based on its options.
mount() → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onAttach() → void
Called when the game has been attached. This can be overridden to add logic that requires the game to already be attached to the widget tree.
onDetach() → void
Called after the game has left the widget tree. This can be overridden to add logic that requires the game not be on the flutter widget tree anymore.
onDispose() → void
Called when the GameWidget is disposed by Flutter.
onGameResize(Vector2 size) → void
This is the resize hook; every time the game widget is resized, this hook is called.
onLoad() FutureOr<void>
Method to perform late initialization of the Game class.
onMount() → void
onRemove() → void
Called when the game is about to be removed from the Flutter widget tree, but before it is actually removed. See the docs for an example on how to do cleanups to avoid memory leaks.
pauseEngine() → void
Pauses the engine game loop execution.
refreshWidget({bool isInternalRefresh = true}) → void
When a Game is attached to a GameWidget, this method will force that widget to be rebuilt. This can be used when updating any property which is implemented within the Flutter tree.
removeGameStateListener(VoidCallback callback) → void
render(Canvas canvas) → void
This should render the game.
resumeEngine() → void
Resumes the engine game loop execution.
stepEngine({double stepTime = 1 / 60}) → void
Steps the engine game loop by one frame. Works only if the engine is in paused state. By default step time is assumed to be 1/60th of a second.
toBeLoaded() FutureOr<void>
To be used for tests that needs to evaluate the game after it has been loaded by the game widget.
toString() String
A string representation of this object.
inherited
update(double dt) → void
This should update the state of the game.

Operators

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