FynkelView class

Shows a game: FynkelView(root: garden) makes a world, adds the root, runs it, and frees it all when the view goes. Each display frame it runs the world's loop (World.update: taps, starts, updates) with what the player did (Input), then hands the world to the engine to draw from its active camera. It fills the space its parent gives it, which must be bounded, so menus and HUDs are Flutter widgets around or on top of it.

A FynkelGame's root is shown in the game's world, which the game makes and disposes, and so is a root already in a world (another view's: a minimap beside it). Any other root, the view adds to a world of its own, which wears the theme around the view (world.theme) from before the root is added. A world a view made goes when the last view showing it goes, so a view Flutter makes again for the same root (one wrapped in a Stack now) goes on with the same game.

The view keeps the root it was first built with (FynkelViewState.root), and a debug build says so when it's given another. To change level, destroy the old root and add the next to its world (root.world) first; to start over, make the root in a FynkelGame (as FynkelApp does) and restart it, or give the view a new key. The world is FynkelViewState.world too, for code outside the game.

The bare view, FynkelView(root:) with no FynkelGame around it, is for a second view of a game or a quick tool: a game starts with FynkelApp, or with a FynkelGame and its view inside a bigger app. Alone, the view can't start the game over (no restart, no F5), and the game's world is there only once the view is built, so a widget beside it can't take game.world.input in the same build, as one in a FynkelGame's builder can.

FynkelView.world(world) shows a world made and driven by hand instead, for tests and tools; the world is the caller's to dispose. onFrame is called each frame with the seconds since the last one, before the world's loop.

A hot reload reads the world's shaders and sounds again (World.reloadAssets), whichever way it was made; a FynkelGame does it for its own.

It gives the world's World.input Flutter's events as they come. It reads pointers with a Listener, which takes part in no gesture arena, so gesture widgets around it keep working, and a widget over it (a HUD's button) keeps the pointers it takes from the game. While it has focus it gives the game every key, and keeps those the game uses (Input.usesKey: bound to an axis or action, or asked about), so the arrows and space move the player rather than focus; the others go on to Flutter's shortcuts too.

In a debug build (showErrors) it shows what the game's code throws over the game, with the object and the line it came from, as well as in the console: World.errors, which it listens to.

The frames never stop: what throws in one (the view's own onFrame, say) is reported to Flutter and the next frame comes. Without the plugin, as in a widget test of the game, the world runs and nothing is drawn; if the view itself fails, its error shows in its place and the world runs on.

The frames are drawn at the widget's size in physical pixels times renderScale and scaled to fit. Below 1 trades sharpness for speed; the view never lowers it by itself.

Several views of one world (a minimap over the game, split screen) each draw it from their own camera, or from the world's main one (World.camera) when it's null, and the world is updated once a frame however many show it. Each draws its frames at its own size and cost; the world's meshes and textures are on the GPU once. One view takes the input: the first of them with input on (a debug build says so when two have it). It aims what's under a finger from its camera (Input.camera); the others keep the taps on them from the game and from the views under them. The game's errors show in one view too (showErrors).

macOS, iOS and Android.

Inheritance
Available extensions

Constructors

FynkelView({Key? key, required GameObject root, AssetSource? source, void onFrame(double dt)?, double renderScale = 1.0, void onStats(FynkelViewStats stats)?, void onViewStats(ViewStats stats)?, FocusNode? focusNode, bool autofocus = true, bool showErrors = kDebugMode, bool pauseWhenCovered = true, Camera? camera, bool input = true, bool worldWidgets = true, bool directToScreen = true, void onError(Object error, StackTrace stack)?, Widget errorBuilder(BuildContext context, Object error, VoidCallback retry)?})
Shows root in a world of the view's own, loading assets from source.
const
FynkelView.world(World world, {Key? key, void onFrame(double dt)?, double renderScale = 1.0, void onStats(FynkelViewStats stats)?, void onViewStats(ViewStats stats)?, FocusNode? focusNode, bool autofocus = true, bool showErrors = kDebugMode, bool pauseWhenCovered = true, Camera? camera, bool input = true, bool worldWidgets = true, bool directToScreen = true, void onError(Object error, StackTrace stack)?, Widget errorBuilder(BuildContext context, Object error, VoidCallback retry)?})
Shows world, made and driven by hand: the caller disposes of it.
const

Properties

autofocus → bool
Whether the view takes focus when it first appears, so keys work before it's tapped.
final
camera → Camera?
The camera the view draws from, read each frame; the world's main one (World.camera) when null. While it isn't a shown object's in the world (not added yet, destroyed, inactive) the view is black: a minimap whose camera goes doesn't show the main picture instead.
final
directToScreen → bool
Phones: whether the view draws straight to the screen, on a layer of its own behind Flutter's view, rather than into a texture Flutter draws (false). On by default. On Android it needs the app's activity to be a FynkelActivity (the guide, §1); on iOS nothing. Flutter then never waits for the game's frames, which on a slower Android phone is the difference between 40 and 60 fps (docs/android-surface-report.md), and never copies them, which keeps an iPhone cool (docs/ios-surface-report.md), while its own UI goes on at the display's rate.
final
errorBuilder → Widget Function(BuildContext context, Object error, VoidCallback retry)?
What shows in the view's place once it has failed (onError): an ErrorWidget unless given. retry starts again with a new view.
final
focusNode → FocusNode?
The view's focus, for keys. One of its own when null.
final
hashCode → int
The hash code for this object.
no setterinherited
input → bool
Whether the view gives the world the player's taps and keys (and takes focus for them). Off for a minimap or the second half of a split screen: of the views of one world, only the first with it on takes input, and a debug build says so when there are two.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onError → void Function(Object error, StackTrace stack)?
Called once when the view fails for good and can't show the game: a GPU device lost or a surface refused more than three times in a minute, or no view at all. The world runs on (a HUD over it still works). For a crash reporter; the error is reported to Flutter too.
final
onFrame → void Function(double dt)?
Called once per frame of the world's (World.targetFrameRate), before its World.update, with the seconds since the previous call (0 the first time). For code that drives the world from outside; a game's own code goes in its objects.
final
onStats → void Function(FynkelViewStats stats)?
Called about once a second with what the view did since the last call.
final
onViewStats → void Function(ViewStats stats)?
Called after each frame the view hands to the engine with the engine's counts since the view was made, for measuring: the frame that first draws a new model is the first whose textureBytes or meshBytes hold its data, and it's on screen once presented goes up after that.
final
pauseWhenCovered → bool
Whether a page or dialog over the view pauses the game (World.paused): a pause menu, a settings page, a pop-up. Closing the last one goes on, unless the game was paused already, or set World.paused itself meanwhile (a game over under the settings page), which it keeps. Covered, the view gets no taps or keys either, and, as nothing in it moves, it's drawn only 10 times a second, which keeps a phone cool behind a menu. Under a page that covers it whole, or in a hidden tab, the world runs the same 10 frames a second, its unscaled time going on, and nothing is drawn; with this false, it runs on at its rate there, unseen.
final
renderScale → double
Pixels drawn per physical pixel: above 0 and at most 4, 1 unless given. Below 1 is faster and softer. It multiplies the world's Quality.renderScale, which a game sets for all its views (a settings page); this is for one view of its own, a minimap say.
final
root → GameObject?
The game: shown in its FynkelGame's world, or in the world it's in already, or else added to the view's own world when the view is first built. The view keeps the first it's given (FynkelViewState.root).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
showErrors → bool
Whether the errors the game's code throws (World.errors) are shown over the game and reported to Flutter (the console, and a failing widget test), rather than left to the game. On in debug builds. Of several views of one world, one shows them: the one taking input if it shows errors, else the first that does.
final
source → AssetSource?
Where the view's own world loads assets from; the app's bundle (bundleSource) when null. A root in a world already loads from that world's: a FynkelGame's, say, is given its source there.
final
world → World?
A world made by hand (FynkelView.world), shown in place of a root's own.
final
worldWidgets → bool
Whether the world's WorldWidgets show over the view, placed by its camera: health bars on each half of a split screen. Off for a minimap.
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<FynkelView>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited
toTexture({required Size size, double pixelRatio = 1}) → Future<Texture2D>

Available on Widget, provided by the WidgetTexture extension

Draws this widget once, size logical pixels at pixelRatio, into a texture size × pixelRatio pixels: off the screen, round it only a Directionality (left to right) and a MediaQuery of size, so a Text needs no app. It isn't live and takes no taps: to change it, draw it again (a scoreboard once a second, not every frame). Images in it must be loaded first (precacheImage), as nothing waits for them. On Android it waits for the app's first frame to be drawn: before then there's no GL context to draw it in.

Operators

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