Fork me on GitHub
View source

package haxepunk

class Entity


extends Tweener
extended by DebugButton, LogPanel, Metric, MouseManager, Cursor, EntityList

Main game Entity class updated by Scene.

Constructor

View source

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

read only bottom : Float

The bottommost position of the Entity's hitbox.

camera : Null<Camera>

read only centerX : Float

The center x position of the Entity's hitbox.

read only centerY : Float

The center y position of the Entity's hitbox.

collidable : Bool

If the Entity should respond to collision checks.

enabled : Bool

followCamera : Null<Camera>

Set to the camera the entity should follow. If null it won't follow any camera.

graphic : Graphic

Graphical component to render to the screen.

read only halfHeight : Float

Half the Entity's height.

read only halfWidth : Float

Half the Entity's width.

height : Int

Height of the Entity's hitbox.

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.

read only left : Float

The leftmost position of the Entity's hitbox.

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

mask : Mask

An optional Mask component, used for specialized collision. If this is not assigned, collision checks will use the Entity's hitbox by default.

name : String

An optional name for the entity.

originX : Int

X origin of the Entity's hitbox.

originY : Int

Y origin of the Entity's hitbox.

parent : Null<Entity>

The entity's parent, if any. This entity's position will be offset by the parent's position.


Available since:

4.0.0

read only right : Float

The rightmost position of the Entity's hitbox.

read only scene : Scene

The Scene object this Entity has been added to.

skipFrames : Int

If set, skip every N update frames.

read only top : Float

The topmost position of the Entity's hitbox.

type : String

The collision type, used for collision checking.

visible : Bool

If the Entity should render.

width : Int

Width of the Entity's hitbox.

x : Float

X position of the Entity in the Scene.

y : Float

Y position of the Entity in the Scene.

Functions

View source

addGraphic (g : Graphic) : Graphic

Adds the graphic to the Entity via a Graphiclist.


Parameters:
g   

Graphic to add.


Returns:

The added graphic.

View source

added () : Void

Override this, called when the Entity is added to a Scene.

View source

centerGraphicInRect () : Void

Center graphic inside bounding rect.

View source

centerOrigin () : Void

Center's the Entity's origin (half width & height).

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

debugDraw (camera : Camera, selected : Bool = false) : Void

View source

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.

View source

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.

View source

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.

View source

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

View source

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

View source

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.

View source

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.

View source

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

View source

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

View source

removed () : Void

Override this, called when the Entity is removed from a Scene.

View source

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.

View source

resized () : Void

Override this, called when the Scene is resized.

View source

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.

View source

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

View source

setOrigin (x : Int = 0, y : Int = 0) : Void

Sets the origin of the Entity.


Parameters:
x   

X origin.

y   

Y origin.

View source

toString () : String

Gets the class name as a string.


Returns:

A string representing the class name.

View source

update () : Void

Updates the Entity.