package haxepunk
class Entity
extends Tweener
extended by DebugButton, LogPanel, Metric, MouseManager, Cursor, EntityList
Main game Entity class updated by Scene
.
Constructor
new (x : Float = 0, y : Float = 0, graphic : Graphic, mask : Mask) : Void
Constructor. Can be used to place the Entity and assign a graphic and mask.
Parameters:
x | X position to place the Entity. | |
y | Y position to place the Entity. | |
graphic | Graphic to assign to the Entity. | |
mask | Mask to assign to the Entity. |
Variables
enabled : Bool
followCamera : Null<Camera>
Set to the camera the entity should follow. If null it won't follow any camera.
layer : Int
The rendering layer of this Entity. Layers are drawn in descending order. Backgrounds will have large (positive) numbers, foregrounds will have small (negative) numbers.
localX : Float
Local X position. If this entity has a parent, this value is relative to the parent's position.
Available since:
4.0.0
localY : Float
Local Y position. If this entity has a parent, this value is relative to the parent's position.
Available since:
4.0.0
An optional Mask component, used for specialized collision. If this is not assigned, collision checks will use the Entity's hitbox by default.
The entity's parent, if any. This entity's position will be offset by the parent's position.
Available since:
4.0.0
Functions
addGraphic (g : Graphic) : Graphic
Adds the graphic to the Entity via a Graphiclist.
Parameters:
g | Graphic to add. |
Returns:
The added graphic.
clampHorizontal (left : Float, right : Float, padding : Float = 0) : Void
Clamps the Entity's hitbox on the x-axis.
Parameters:
left | Left bounds. | |
right | Right bounds. | |
padding | Optional padding on the clamp. |
clampVertical (top : Float, bottom : Float, padding : Float = 0) : Void
Clamps the Entity's hitbox on the y axis.
Parameters:
top | Min bounds. | |
bottom | Max bounds. | |
padding | Optional padding on the clamp. |
collide (type : String, x : Float, y : Float) : Entity
Checks for a collision against an Entity type.
Parameters:
type | The Entity type to check for. | |
x | Virtual x position to place this Entity. | |
y | Virtual y position to place this Entity. |
Returns:
The first Entity collided with, or null if none were collided.
collideInto<E> (type : String, x : Float, y : Float, array : Array<E>) : Void
Populates an array with all collided Entities of a type. This function does not empty the array, that responsibility is left to the user.
Parameters:
type | The Entity type to check for. | |
x | Virtual x position to place this Entity. | |
y | Virtual y position to place this Entity. | |
array | The Array or Vector object to populate. |
collidePoint (x : Float, y : Float, pX : Float, pY : Float) : Bool
Checks if this Entity overlaps the specified position.
Parameters:
x | Virtual x position to place this Entity. | |
y | Virtual y position to place this Entity. | |
pX | X position. | |
pY | Y position. |
Returns:
If the Entity intersects with the position.
collideRect (x : Float, y : Float, rX : Float, rY : Float, rWidth : Float, rHeight : Float) : Bool
Checks if this Entity overlaps the specified rectangle.
Parameters:
x | Virtual x position to place this Entity. | |
y | Virtual y position to place this Entity. | |
rX | X position of the rectangle. | |
rY | Y position of the rectangle. | |
rWidth | Width of the rectangle. | |
rHeight | Height of the rectangle. |
Returns:
If they overlap.
collideTypes (types : SolidType, x : Float, y : Float) : Entity
Checks for collision against multiple Entity types.
Parameters:
types | An Array or Vector of Entity types to check for. | |
x | Virtual x position to place this Entity. | |
y | Virtual y position to place this Entity. |
Returns:
The first Entity collided with, or null if none were collided.
collideTypesInto<E> (types : Array<String>, x : Float, y : Float, array : Array<E>) : Void
Populates an array with all collided Entities of multiple types. This function does not empty the array, that responsibility is left to the user.
Parameters:
types | An array of Entity types to check for. | |
x | Virtual x position to place this Entity. | |
y | Virtual y position to place this Entity. | |
array | The Array or Vector object to populate. |
collideWith<E> (e : E, x : Float, y : Float) : E
Checks if this Entity collides with a specific Entity.
Parameters:
e | The Entity to collide against. | |
x | Virtual x position to place this Entity. | |
y | Virtual y position to place this Entity. |
Returns:
The Entity if they overlap, or null if they don't.
distanceFrom (e : Entity, useHitboxes : Bool = false) : Float
Calculates the distance from another Entity.
Parameters:
e | The other Entity. | |
useHitboxes | If hitboxes should be used to determine the distance. If not, the Entities' x/y positions are used. |
Returns:
The distance.
distanceToPoint (px : Float, py : Float, useHitbox : Bool = false) : Float
Calculates the distance from this Entity to the point.
Parameters:
px | X position. | |
py | Y position. | |
useHitboxes | If hitboxes should be used to determine the distance. If not, the Entities' x/y positions are used. |
Returns:
The distance.
distanceToRect (rx : Float, ry : Float, rwidth : Float, rheight : Float) : Float
Calculates the distance from this Entity to the rectangle.
Parameters:
rx | X position of the rectangle. | |
ry | Y position of the rectangle. | |
rwidth | Width of the rectangle. | |
rheight | Height of the rectangle. |
Returns:
The distance.
moveAtAngle (angle : Float, amount : Float, solidType : SolidType, sweep : Bool = false) : Void
Moves at an angle by a certain amount, retaining integer values for its x and y.
Parameters:
angle | Angle to move at in degrees. | |
amount | Amount to move. | |
solidType | An optional collision type to stop flush against upon collision. | |
sweep | If sweeping should be used (prevents fast-moving objects from going through solidType). |
moveBy (x : Float, y : Float, solidType : SolidType, sweep : Bool = false) : Void
Moves the Entity by the amount, retaining integer values for its x and y.
Parameters:
x | Horizontal offset. | |
y | Vertical offset. | |
solidType | An optional collision type to stop flush against upon collision. | |
sweep | If sweeping should be used (prevents fast-moving objects from going through solidType). |
moveCollideX (e : Entity) : Bool
When you collide with an Entity on the x-axis with moveTo() or moveBy() the engine call this function. Override it to detect and change the behaviour of collisions.
Parameters:
e | The Entity you collided with. |
Returns:
If there was a collision.
moveCollideY (e : Entity) : Bool
When you collide with an Entity on the y-axis with moveTo() or moveBy() the engine call this function. Override it to detect and change the behaviour of collisions.
Parameters:
e | The Entity you collided with. |
Returns:
If there was a collision.
moveTo (x : Float, y : Float, solidType : SolidType, sweep : Bool = false) : Void
Moves the Entity to the position, retaining integer values for its x and y.
Parameters:
x | X position. | |
y | Y position. | |
solidType | An optional collision type to stop flush against upon collision. | |
sweep | If sweeping should be used (prevents fast-moving objects from going through solidType). |
moveTowards (x : Float, y : Float, amount : Float, solidType : SolidType, sweep : Bool = false) : Void
Moves towards the target position, retaining integer values for its x and y.
Parameters:
x | X target. | |
y | Y target. | |
amount | Amount to move. | |
solidType | An optional collision type to stop flush against upon collision. | |
sweep | If sweeping should be used (prevents fast-moving objects from going through solidType). |
render (camera : Camera) : Void
Renders the Entity. If you override this for special behaviour, remember to call super.render() to render the Entity's graphic.
setHitbox (width : Int = 0, height : Int = 0, originX : Int = 0, originY : Int = 0) : Void
Sets the Entity's hitbox properties.
Parameters:
width | Width of the hitbox. | |
height | Height of the hitbox. | |
originX | X origin of the hitbox. | |
originY | Y origin of the hitbox. |
setHitboxTo (o : Dynamic) : Void
Sets the Entity's hitbox to match that of the provided object.
Parameters:
o | The object defining the hitbox (eg. an Image or Rectangle). |
setOrigin (x : Int = 0, y : Int = 0) : Void
Sets the origin of the Entity.
Parameters:
x | X origin. | |
y | Y origin. |
toString () : String
Gets the class name as a string.
Returns:
A string representing the class name.