FixedResolutionViewport class

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.

To accomplish this you choose a virtual size that will always match the effective size.

Under the hood, the Viewport will try to expand (or contract) the virtual size so that it fits the most of the screen as it can. So for example, if the viewport happens to be the same ratio of the screen, it will resize to fit 100%. But if they are different ratios, it will resize the most it can and then will add black (color is configurable) borders.

Then, inside your game, you can always assume the game size is the fixed dimension that you provided.

Normally you can pick a virtual size that has the same ratio as the most used device for your game (like a pretty standard mobile ratio if you are doing a mobile game) and then in most cases this will apply no transformation whatsoever, and if the a device with a different ratio is used it will try to adapt the best as possible.

Inheritance

Constructors

FixedResolutionViewport(Vector2 effectiveSize, {bool noClip = false})

Properties

canvasSize Vector2?
This returns the real widget size (well actually the logical Flutter size of your widget). This is the raw canvas size as it would be without any viewport.
getter/setter pairinherited
effectiveSize Vector2
This returns the effective size, after viewport transformation. This is not the game widget size but for all intents and purposes, inside your game, this size should be used as the real one.
getter/setter pairoverride-getter
hashCode int
The hash code for this object.
no setterinherited
noClip bool
By default, this viewport will clip anything rendered outside. Use this variable to control that behaviour.
getter/setter pair
resizeOffset Vector2
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scale double
no setter
scaledSize Vector2
no setter

Methods

apply(Canvas c) → void
Applies to the Canvas all necessary transformations to apply this viewport.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
projectVector(Vector2 viewportCoordinates) Vector2
Converts a vector in the world space to the screen space.
override
render(Canvas c, void renderGame(Canvas)) → void
This transforms the canvas so that the coordinate system is viewport- -aware. All your rendering logic should be put inside the lambda.
inherited
resize(Vector2 newCanvasSize) → void
This configures the viewport with a new raw canvas size. It should immediately affect effectiveSize and canvasSize. This must be called by the engine at startup and also whenever the size changes.
override
scaleVector(Vector2 viewportCoordinates) Vector2
Converts a vector representing a delta in the world space to the screen space.
override
toString() String
A string representation of this object.
inherited
unprojectVector(Vector2 screenCoordinates) Vector2
Converts a vector in the screen space to the world space.
override
unscaleVector(Vector2 screenCoordinates) Vector2
Converts a vector representing a delta in the screen space to the world space.
override

Operators

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