Anchor class

Represents a relative position inside some 2D object with a rectangular size or bounding box.

Think of it as the place where you "grab" or "hold" the object. In Components, the Anchor is where the component position is measured from. For example, if a component position is (100, 100) the anchor reflects what exact point of the component that is positioned at (100, 100), as a relative fraction of the size of the object.

The "default" anchor in most cases is topLeft.

The Anchor is represented by a fraction of the size (in each axis), where 0 in x-axis means left, 0 in y-axis means top, 1 in x-axis means right and 1 in y-axis means bottom.

Annotations

Constructors

Anchor(double x, double y)
const
Anchor.valueOf(String name)
This should only be used for de-serialization purposes.
factory

Properties

hashCode int
The hash code for this object.
no setteroverride
name String
Returns a string representation of this Anchor.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
x double
The relative x position with respect to the object's width; 0 means totally to the left (beginning) and 1 means totally to the right (end).
final
y double
The relative y position with respect to the object's height; 0 means totally to the top (beginning) and 1 means totally to the bottom (end).
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toOtherAnchorPosition(Vector2 position, Anchor otherAnchor, Vector2 size, {Vector2? out}) Vector2
Take your position position that is on this anchor and give back what that position it would be on in anchor otherAnchor with a size of size.
toString() String
Returns a string representation of this Anchor.
override
toVector2() Vector2
Returns x and y as a Vector2. Note that this is still a relative fractional representation.

Operators

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

Static Properties

values List<Anchor>
List of all predefined anchor values.
final

Constants

bottomCenter → const Anchor
bottomLeft → const Anchor
bottomRight → const Anchor
center → const Anchor
centerLeft → const Anchor
centerRight → const Anchor
topCenter → const Anchor
topLeft → const Anchor
topRight → const Anchor