Game mixin

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

Add this mixin to your game class and implement the update and render methods to use it in a GameWidget. Flame will deal with calling these methods properly when the game's widget is rendered.

Mixin Applications

Properties

assets AssetsCache
final
buildContext BuildContext?
Currently attached build context. Can be null if not attached.
no setter
canvasSize Vector2
no setter
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
final
isAttached bool
Whether the game widget was attached to the Flutter tree.
no setter
mouseCursor ValueNotifier<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.
final
onLoadFuture Future<void>?
This variable ensures that Game's onLoad is called no more than once.
getter/setter pair
overlays ActiveOverlaysNotifier
A property that stores an ActiveOverlaysNotifier
final
paused bool
Returns is the engine if currently paused or running
getter/setter pair
pauseEngineFn VoidCallback?
getter/setter pair
projector Projector
This is the projector used by all components that respect the camera (respectCamera = true). This can be overridden on your Game implementation.
getter/setter pair
resumeEngineFn VoidCallback?
getter/setter pair
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
viewportProjector Projector
This is the projector used by components that don't respect the camera (positionType = PositionType.viewport;). This can be overridden on your Game implementation.
getter/setter pair

Methods

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.
lifecycleStateChange(AppLifecycleState state) → void
This is the lifecycle state change hook; every time the game is resumed, paused or suspended, this is called.
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.
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.
onGameResize(Vector2 size) → void
This is the resize hook; every time the game widget is resized, this hook is called.
onLoad() Future<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.
onTimingsCallback(List<FrameTiming> timings) → void
Use for calculating the FPS.
pauseEngine() → void
Pauses the engine game loop execution.
render(Canvas canvas) → void
This should render the game.
resumeEngine() → void
Resumes the engine game loop execution.
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