game library

Classes

Aabb2
Defines a 2-dimensional axis-aligned bounding box between a min and a max position.
Aabb3
Defines a 3-dimensional axis-aligned bounding box between a min and a max position.
Camera
A camera translates your game coordinate system; this is useful when your world is not 1:1 with your screen size.
ComposedProjector
This is a Projector implementation that composes a list of projectors, in the order provided.
DefaultViewport
This is the default viewport if you want no transformation. The raw canvasSize is just propagated to the effective size and no translation is applied. This basically no-ops the viewport.
FixedResolutionViewport
This is the most common viewport if you want to have full control of what the game looks like. Basically this viewport makes sure the ratio between width and height is always the same in your game, no matter the platform.
FlameGame<W extends World>
This is a more complete and opinionated implementation of Game.
Frustum
Defines a frustum constructed out of six Planes.
Game
This gives access to a low-level game API, to not build everything from a low level FlameGame should be used.
GameWidget<T extends Game>
The GameWidget is a Flutter widget which is used to insert a Game instance into the Flutter widget tree.
GameWidgetState<T extends Game>
IdentityProjector
A simple Projector implementation that represents the identity operation (i.e. no-op).
IntersectionResult
Defines a result of an intersection test.
Matrix2
2D Matrix. Values are stored in column major order.
Matrix3
3D Matrix. Values are stored in column major order.
Matrix4
4D Matrix. Values are stored in column major order.
NotifyingVector2
Extension of the standard Vector2 class, implementing the ChangeNotifier functionality. This allows any interested party to be notified when the value of this vector changes.
Obb3
Defines a 3-dimensional oriented bounding box defined with a center, halfExtents and axes.
OverlayRoute
OverlayRoute is a class that allows adding/removing game overlays as if they were ordinary Routes.
Plane
Projector
A simple interface to mark a class that can perform projection operations from one 2D Euclidean coordinate space to another.
Quad
Defines a quad by four points.
Quaternion
Defines a Quaternion (a four-dimensional vector) for efficient rotation calculations.
Ray
Defines a Ray by an origin and a direction.
Route
Route is a light-weight component that builds and manages a page.
RouterComponent
RouterComponent handles transitions between multiple pages of a game.
SimplexNoise
Sphere
Defines a sphere with a center and a radius.
TextPaint
TextPaint applies a Flutter TextStyle to a string of text, creating a TextPainterTextElement.
Transform2D
This class describes a generic 2D transform, which is a combination of translations, rotations, reflections and scaling. These transforms are combined into a single matrix, that can be either applied to a canvas, composed with another transform, or used directly to convert coordinates.
Triangle
Defines a triangle by three points.
ValueRoute<T>
ValueRoute is a special route that "returns a value" when popped.
Vector
Base class for vectors
Vector2
2D column vector.
Vector3
3D column vector.
Vector4
4D column vector.
Viewport
A viewport is a class that potentially translates and resizes the screen. The reason you might want to have a viewport is to make sure you handle any screen size and resolution correctly depending on your needs.

Mixins

HasCollisionDetection<B extends Broadphase<ShapeHitbox>>
Keeps track of all the ShapeHitboxs in the component's tree and initiates collision detection every tick.
HasDraggables
HasGenericCollisionDetection<T extends Hitbox<T>, B extends Broadphase<T>>
This mixin is useful if you have written your own collision detection which isn't operating on ShapeHitbox since you can have any hitbox here.
HasHoverables
HasTappables
Mixin that can be added to a FlameGame allowing it (and the components attached to it) to receive tap events.
SingleGameInstance
Mixin that declares a Game class as a singleton.

Extensions

Vector2Extension

Constants

degrees2Radians → const double
Constant factor to convert and angle from degrees to radians.
math.pi / 180.0
radians2Degrees → const double
Constant factor to convert and angle from radians to degrees.
180.0 / math.pi

Functions

absoluteError(dynamic calculated, dynamic correct) double
Returns absolute error between calculated and correct. The type of calculated and correct must match and can be any vector, matrix, or quaternion.
buildPlaneVectors(Vector3 planeNormal, Vector3 u, Vector3 v) → void
Sets u and v to be two vectors orthogonal to each other and planeNormal.
catmullRom(double edge0, double edge1, double edge2, double edge3, double amount) double
Do a catmull rom spline interpolation with edge0, edge1, edge2 and edge3 by amount.
cross2(Vector2 x, Vector2 y) double
2D cross product. vec2 x vec2.
cross2A(double x, Vector2 y, Vector2 out) → void
2D cross product. double x vec2.
cross2B(Vector2 x, double y, Vector2 out) → void
2D cross product. vec2 x double.
cross3(Vector3 x, Vector3 y, Vector3 out) → void
3D Cross product.
degrees(double radians) double
Convert radians to degrees.
dot2(Vector2 x, Vector2 y) double
2D dot product.
dot3(Vector3 x, Vector3 y) double
3D dot product.
makeFrustumMatrix(double left, double right, double bottom, double top, double near, double far) Matrix4
Constructs a new OpenGL perspective projection matrix.
makeInfiniteMatrix(double fovYRadians, double aspectRatio, double zNear) Matrix4
Constructs a new OpenGL infinite projection matrix.
makeOrthographicMatrix(double left, double right, double bottom, double top, double near, double far) Matrix4
Constructs a new OpenGL orthographic projection matrix.
makePerspectiveMatrix(double fovYRadians, double aspectRatio, double zNear, double zFar) Matrix4
Constructs a new OpenGL perspective projection matrix.
makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) Matrix4
Returns a transformation matrix that transforms points onto the plane specified with planeNormal and planePoint.
makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) Matrix4
Returns a transformation matrix that transforms points by reflecting them through the plane specified with planeNormal and planePoint.
makeViewMatrix(Vector3 cameraPosition, Vector3 cameraFocusPosition, Vector3 upDirection) Matrix4
Constructs a new OpenGL view matrix.
mix(double min, double max, double a) double
Interpolate between min and max with the amount of a using a linear interpolation. The computation is equivalent to the GLSL function mix.
pickRay(Matrix4 cameraMatrix, num viewportX, num viewportWidth, num viewportY, num viewportHeight, num pickX, num pickY, Vector3 rayNear, Vector3 rayFar) bool
On success, rayNear and rayFar are the points where the screen space pickX, pickY intersect with the near and far planes respectively.
radians(double degrees) double
Convert degrees to radians.
relativeError(dynamic calculated, dynamic correct) double
Returns relative error between calculated and correct. The type of calculated and correct must match and can be any vector, matrix, or quaternion.
setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right, double bottom, double top, double near, double far) → void
Constructs an OpenGL perspective projection matrix in perspectiveMatrix.
setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians, double aspectRatio, double zNear) → void
Constructs an OpenGL infinite projection matrix in infiniteMatrix. fovYRadians specifies the field of view angle, in radians, in the y direction. aspectRatio specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio of x (width) to y (height). zNear specifies the distance from the viewer to the near plane (always positive).
setModelMatrix(Matrix4 modelMatrix, Vector3 forwardDirection, Vector3 upDirection, double tx, double ty, double tz) → void
Constructs an OpenGL model matrix in modelMatrix. Model transformation is the inverse of the view transformation. Model transformation is also known as "camera" transformation. Model matrix is commonly used to compute a object location/orientation into the full model-view stack.
setOrthographicMatrix(Matrix4 orthographicMatrix, double left, double right, double bottom, double top, double near, double far) → void
Constructs an OpenGL orthographic projection matrix in orthographicMatrix.
setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians, double aspectRatio, double zNear, double zFar) → void
Constructs an OpenGL perspective projection matrix in perspectiveMatrix.
setRotationMatrix(Matrix4 rotationMatrix, Vector3 forwardDirection, Vector3 upDirection) → void
Constructs a rotation matrix in rotationMatrix.
setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition, Vector3 cameraFocusPosition, Vector3 upDirection) → void
Constructs an OpenGL view matrix in viewMatrix. View transformation is the inverse of the model transformation. View matrix is commonly used to compute the camera location/orientation into the full model-view stack.
smoothStep(double edge0, double edge1, double amount) double
Do a smooth step (hermite interpolation) interpolation with edge0 and edge1 by amount. The computation is equivalent to the GLSL function smoothstep.
unproject(Matrix4 cameraMatrix, num viewportX, num viewportWidth, num viewportY, num viewportHeight, num pickX, num pickY, num pickZ, Vector3 pickWorld) bool
On success, Sets pickWorld to be the world space position of the screen space pickX, pickY, and pickZ.

Typedefs

GameErrorWidgetBuilder = Widget Function(BuildContext, Object error)
GameFactory<T extends Game> = T Function()
GameLoadingWidgetBuilder = Widget Function(BuildContext)
OverlayWidgetBuilder<T extends Game> = Widget Function(BuildContext context, T game)