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.



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


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).
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).


noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
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.
toVector2() Vector2
Returns x and y as a Vector2. Note that this is still a relative fractional representation.


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

Static Properties

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


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