Anchor extension type
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 nodes, the anchor is where the node position is measured from. For example, if a node's position is (100, 100) the anchor reflects what exact point of the node 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.
Just a Vector2 under the hood, with canonical instances for common positions.
Original concept and comments from Flame.
- on
- Implemented types
- Available extensions
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isInfinite → bool
-
True if any component is infinite.
no setterinherited
- isNaN → bool
-
True if any component is NaN.
no setterinherited
- isZero → bool
-
True if both components are zero.
no setterinherited
- length → double
-
The length of the vector.
no setterinherited
- length2 → double
-
The squared length of the vector.
no setterinherited
- opposite → Anchor
-
Returns the anchor on the opposite side of this anchor.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → Vector2
-
final
- 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).
no setter
- 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).
no setter
Methods
-
angleTo(
Vector2 other) → double -
Returns the angle between this vector and
otherin radians.inherited -
angleToSigned(
Vector2 other) → double -
Returns the signed angle between this and
otherin radians.inherited -
axis(
Axis axis) → double -
Available on Vector2, provided by the AxisVector2 extension
The component alongaxis: x if horizontal, y if vertical. -
ceiled(
) → Vector2 -
Ceiled copy of this.
inherited
-
clamped(
Vector2 range) → Vector2 -
Copy of this with each component clamped between
range.xandrange.y.inherited -
clampedBetween(
Vector2 min, Vector2 max) → Vector2 -
Copy of this with each component clamped between the matching components
of
minandmax.inherited -
clampedTo(
double min, double max) → Vector2 -
Copy of this with each component clamped between
minandmax.inherited -
clampedToX(
double min, double max) → Vector2 -
Copy of this with the x component clamped between
minandmax.inherited -
clampedToY(
double min, double max) → Vector2 -
Copy of this with the y component clamped between
minandmax.inherited -
clampedX(
Vector2 range) → Vector2 -
Copy of this with the x component clamped between
range.xandrange.y.inherited -
clampedY(
Vector2 range) → Vector2 -
Copy of this with the y component clamped between
range.xandrange.y.inherited -
clone(
) → Vector2 -
Clone of this.
inherited
-
cross(
Vector2 other) → double -
Cross product.
inherited
-
distance(
Vector2 other) → double -
Distance from this to
other.inherited -
distance2(
Vector2 other) → double -
Squared distance from this to
other.inherited -
dot(
Vector2 other) → double -
Inner product.
inherited
-
floored(
) → Vector2 -
Floored copy of this.
inherited
-
multiplied(
Vector2 other) → Vector2 -
Copy of this multiplied by
other.inherited -
normalized(
) → Vector2 -
Normalized copy of this.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reflected(
Vector2 normal) → Vector2 -
Reflected copy of this.
inherited
-
rounded(
) → Vector2 -
Rounded copy of this.
inherited
-
roundedToZero(
) → Vector2 -
Copy of this, rounded towards zero.
inherited
-
scaled(
double value) → Vector2 -
Return a copy of this scaled by
value.inherited -
toString(
) → String -
Returns a printable string.
inherited
-
transformed(
Matrix3 matrix) → Vector2 -
Transforms this by
matrixand returns the result.inherited
Operators
-
operator *(
double value) → Vector2 -
Scale.
inherited
-
operator +(
Vector2 other) → Vector2 -
Add two vectors.
inherited
-
operator -(
Vector2 other) → Vector2 -
Subtract two vectors.
inherited
-
operator /(
double value) → Vector2 -
Scale.
inherited
-
operator ==(
Object other) → bool -
Check if two vectors are the same.
inherited
-
operator [](
int index) → double -
Access the component of the vector at the index
index.inherited -
operator unary-(
) → Vector2 -
Negate.
inherited
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