Entity2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and skew.
A 2D game object, inherited by all 2D-related entities. Has a position, rotation, scale, and skew.
A 2D game object, with a transform (position, rotation, and scale). All 2D entities, including physics objects and sprites, inherit from Entity2D. Use Entity2D as a parent entity to move, scale and rotate children in a 2D project. Also gives control of the entity's render order.
Note: Since both Entity2D and Control inherit from CanvasItem, they share several concepts from the class such as the CanvasItem.ZIndex and CanvasItem.Visible properties.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
Entity2DConstructor
public Entity2D();Properties12
GlobalPositionProperty
public Vector2 GlobalPosition { get; set; }Origin position in the item's canvas, excluding camera and window transforms. Assignment converts the point through the parent CanvasItem inverse transform; when a parent applies, its basis must be invertible.
GlobalRotationProperty
public float GlobalRotation { get; set; }Global rotation in radians. See also Entity2D.Rotation.
GlobalRotationDegreesProperty
public float GlobalRotationDegrees { get; set; }Helper property to access Entity2D.GlobalRotation in degrees instead of radians. See also Entity2D.RotationDegrees.
GlobalScaleProperty
public Vector2 GlobalScale { get; set; }Global scale. See also Entity2D.Scale.
GlobalSkewProperty
public float GlobalSkew { get; set; }Global skew in radians. See also Entity2D.Skew.
GlobalTransformProperty
public Transform2D GlobalTransform { get; set; }Affine transform from item-local coordinates to its canvas, including inherited CanvasItem ancestors. Does not include Camera2D, CanvasLayer or final window presentation; use GetGlobalTransformWithCanvas for the canvas stage.
PositionProperty
public Vector2 Position { get; set; }Origin position in the parent CanvasItem local space. Parent rotation and scale affect the resulting GlobalPosition. With TopLevel the parent CanvasItem transform is not inherited.
RotationProperty
public float Rotation { get; set; }Rotation in radians, relative to the entity's parent. See also Entity2D.GlobalRotation.
Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use Entity2D.RotationDegrees.
RotationDegreesProperty
public float RotationDegrees { get; set; }Helper property to access Entity2D.Rotation in degrees instead of radians. See also Entity2D.GlobalRotationDegrees.
ScaleProperty
public Vector2 Scale { get; set; }The entity's scale, relative to the entity's parent. Unscaled value: (1, 1). See also Entity2D.GlobalScale.
Note: Negative X scales in 2D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Reckfell, negative scales on the X axis will be changed to negative scales on the Y axis and a rotation of 180 degrees when decomposed.
SkewProperty
public float Skew { get; set; }If set to a non-zero value, slants the entity in one direction or another. This can be used for pseudo-3D effects. See also Entity2D.GlobalSkew.
Note: Skew is performed on the X axis only, and between rotation and scaling.
Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use skew = deg_to_rad(value_in_degrees).
TransformProperty
public Transform2D Transform { get; set; }Item-local affine transform: basis and translation relative to the parent CanvasItem. Hierarchy composition uses parentTransform * childTransform.
Methods33
ApplyScalevoid
public void ApplyScale(Vector2 ratio);Multiplies the current scale by the ratio vector.
| Name | Type | Default |
|---|---|---|
ratio | Vector2 | — |
GetAngleTofloat
public float GetAngleTo(Vector2 point);Returns an angle in radians for a world-space point relative to this Entity2D. The implementation takes the angle of ToLocal(point) multiplied componentwise by the entity Scale. Keep the point in world coordinates; the result depends on the current transform. See also Entity2D.LookAt.
| Name | Type | Default |
|---|---|---|
point | Vector2 | — |
floatGetGlobalPositionVector2
public Vector2 GetGlobalPosition();Vector2GetGlobalRotationfloat
public float GetGlobalRotation();floatGetGlobalRotationDegreesfloat
public float GetGlobalRotationDegrees();floatGetGlobalScaleVector2
public Vector2 GetGlobalScale();Vector2GetGlobalSkewfloat
public float GetGlobalSkew();floatGetPositionVector2
public Vector2 GetPosition();Vector2GetRelativeTransformToParentTransform2D
public Transform2D GetRelativeTransformToParent(Entity parent);Composes the transform to the specified ancestor through an Entity2D parent chain; returns identity for the item itself. This is not a conversion between arbitrary siblings and does not include canvas/camera transforms.
| Name | Type | Default |
|---|---|---|
parent | Entity | — |
parentThe item itself or an ancestor reachable through an Entity2D chain.
Transform2DTransform from item-local space to the specified Entity2D ancestor space.
GetRotationfloat
public float GetRotation();floatGetRotationDegreesfloat
public float GetRotationDegrees();floatGetScaleVector2
public Vector2 GetScale();Vector2GetSkewfloat
public float GetSkew();floatGlobalTranslatevoid
public void GlobalTranslate(Vector2 offset);Adds the offset vector to the entity's global position.
| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
LookAtvoid
public void LookAt(Vector2 point);Rotates the entity so that its local +X axis points towards the point, which is expected to use global coordinates. This method is a combination of both Entity2D.Rotate and Entity2D.GetAngleTo.
point should not be the same as the entity's position, otherwise the entity always looks to the right.
| Name | Type | Default |
|---|---|---|
point | Vector2 | — |
MoveLocalXvoid
public void MoveLocalX(float delta, bool scaled = false);Applies a local translation on the entity's X axis with the amount specified in delta. If scaled is false, normalizes the movement to occur independently of the entity's Entity2D.Scale.
| Name | Type | Default |
|---|---|---|
delta | float | — |
scaled | bool | false |
MoveLocalYvoid
public void MoveLocalY(float delta, bool scaled = false);Applies a local translation on the entity's Y axis with the amount specified in delta. If scaled is false, normalizes the movement to occur independently of the entity's Entity2D.Scale.
| Name | Type | Default |
|---|---|---|
delta | float | — |
scaled | bool | false |
Rotatevoid
public void Rotate(float radians);Applies a rotation to the entity, in radians, starting from its current rotation. This is equivalent to rotation += radians.
| Name | Type | Default |
|---|---|---|
radians | float | — |
SetGlobalPositionvoid
public void SetGlobalPosition(Vector2 position);| Name | Type | Default |
|---|---|---|
position | Vector2 | — |
SetGlobalRotationvoid
public void SetGlobalRotation(float radians);| Name | Type | Default |
|---|---|---|
radians | float | — |
SetGlobalRotationDegreesvoid
public void SetGlobalRotationDegrees(float degrees);| Name | Type | Default |
|---|---|---|
degrees | float | — |
SetGlobalScalevoid
public void SetGlobalScale(Vector2 scale);| Name | Type | Default |
|---|---|---|
scale | Vector2 | — |
SetGlobalSkewvoid
public void SetGlobalSkew(float radians);| Name | Type | Default |
|---|---|---|
radians | float | — |
SetGlobalTransformvoid
public void SetGlobalTransform(Transform2D xform);| Name | Type | Default |
|---|---|---|
xform | Transform2D | — |
SetPositionvoid
public void SetPosition(Vector2 position);| Name | Type | Default |
|---|---|---|
position | Vector2 | — |
SetRotationvoid
public void SetRotation(float radians);| Name | Type | Default |
|---|---|---|
radians | float | — |
SetRotationDegreesvoid
public void SetRotationDegrees(float degrees);| Name | Type | Default |
|---|---|---|
degrees | float | — |
SetScalevoid
public void SetScale(Vector2 scale);| Name | Type | Default |
|---|---|---|
scale | Vector2 | — |
SetSkewvoid
public void SetSkew(float radians);| Name | Type | Default |
|---|---|---|
radians | float | — |
SetTransformvoid
public void SetTransform(Transform2D xform);| Name | Type | Default |
|---|---|---|
xform | Transform2D | — |
ToGlobalVector2
public Vector2 ToGlobal(Vector2 localPoint);Converts an item-local point to its canvas coordinates using GlobalTransform. Does not add the camera or window transform. Passing the item's own Position instead of a local point usually applies its offset twice.
| Name | Type | Default |
|---|---|---|
localPoint | Vector2 | — |
localPointPoint relative to this Entity2D itself, not its parent-relative Position.
Vector2Point in the item's canvas, not a screen position.
ToLocalVector2
public Vector2 ToLocal(Vector2 globalPoint);Converts a point from the item's canvas to item-local coordinates using the affine inverse of GlobalTransform. This does not convert an OS screen position or a camera-transformed logical viewport point; the basis must be invertible.
| Name | Type | Default |
|---|---|---|
globalPoint | Vector2 | — |
globalPointPoint in this item's canvas, excluding the camera transform.
Vector2Point in the Entity2D local space.
Translatevoid
public void Translate(Vector2 offset);Translates the entity by the given offset in local coordinates. This is equivalent to position += offset.
| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |