API Docs for: 1.4.0
Show:

Kiwi.Entity Class

Defined in: src\core\Entity.ts:9
Module: Kiwi

An Entity is a base class for game objects to extend from and thus you should never directly instantiate this class. Every entity requires that you pass to it the state to which it belongs, so that when you switch states the appropriate entities can be deleted.

Constructor

Kiwi.Entity

(
  • state
  • x
  • y
)
Kiwi.Entity

Parameters:

  • state State

    The state that this entity belongs to. Used to generate the Unique ID and for garbage collection.

  • x Number

    The entities position on the x axis.

  • y Number

    The entities position on the y axis.

Returns:

Kiwi.Entity:

This entity.

Methods

addTag

(
  • tag
)
public

Defined in src\core\Entity.ts:464

Available since 1.1.0

Adds a new Tag to this Entity. Useful for identifying large amounts of the same type of GameObjects. You can pass multiple strings to add multiple tags.

Parameters:

  • tag String

    The tag that you would like to add to this Entity.

centerAnchorPoint

() public

Defined in src\core\Entity.ts:332

Available since 1.1.0

Center the anchor point. Moves the anchor point (rotPointX and Y) to precisely halfway along the width and height properties of this Entity.

destroy

(
  • [immediate=false]
)
public

Used to completely destroy this entity and of its components. Used for garbage collection and developers can also use it as needed. It is more reliable to use "exists = false", as this will ensure that "destroy" is called at a convenient time.

Parameters:

  • [immediate=false] Boolean optional

    If the object should be immediately removed or if it should be removed at the end of the next update loop.

hasTag

(
  • tag
)
Boolean public

Defined in src\core\Entity.ts:499

Available since 1.1.0

Checks to see if this Entity has a Tag based upon a string which you pass.

Parameters:

  • tag String

Returns:

Boolean:

objType

() String public

The type of this object.

Returns:

String:

"Entity"

removeTag

(
  • tag
)
public

Defined in src\core\Entity.ts:483

Available since 1.1.0

Removes a Tag from this Entity.

Parameters:

  • tag String

    The tag that you would like to remove from this Entity.

render

(
  • camera
)
public

Renders the entity using the canvas renderer. This isn't called until the Entity has been added to a Group/State which is active. This functionality is handled by the sub classes.

Parameters:

  • camera Camera

renderGL

(
  • camera
  • gl
  • [params=null]
)
public

Renders the entity using the canvas renderer. This isn't called until the Entity has been added to a Group/State which is active. This functionality is handled by the sub classes.

Parameters:

  • camera Kiwi.Camera
  • gl WebGLRenderingContext
  • [params=null] Object optional

    params

scaleToHeight

(
  • value
)
public

Defined in src\core\Entity.ts:321

Available since 1.1.0

Scale to desired height, preserving aspect ratio. This function changes the scale, not the height. If the height changes, for example, as part of an animation sequence, the Entity will retain the new scale.

Parameters:

  • value Number

    The desired height in pixels.

scaleToWidth

(
  • value
)
public

Defined in src\core\Entity.ts:310

Available since 1.1.0

Scale to desired width, preserving aspect ratio. This function changes the scale, not the width. If the width changes, for example, as part of an animation sequence, the Entity will retain the new scale.

Parameters:

  • value Number

    The desired width in pixels.

update

() public

This isn't called until the Entity has been added to a Group or a State. Note: If added to a Group, who is not 'active' (so the Groups update loop doesn't run) then each member will not execute either.

Properties

_active

Boolean private

An active Entity is one that has its update method called by its parent.

Default: true

_alpha

Number private

The alpha of this entity.

_cellIndex

Number private

Holds the current cell that is being used by the entity.

Default: 0

_clock

Kiwi.Clock private

The clock that this entity use's for time based calculations. This generated by the state on instatiation.

_dirty

Boolean private

A value used by components to control if the Entity needs re-rendering

_exists

Boolean private

If an Entity no longer exists it is cleared for garbage collection or pool re-allocation

_inputEnabled

Boolean deprecated private

Defined in src\core\Entity.ts:568

Deprecated: As of 1.2.3, nothing was found to use this.

Controls if this Entity is input enabled or not (i.e. responds to touch/mouse events)

_parent

Kiwi.Group private

The group that this entity belongs to. If added onto the state then this is the state.

_tags

Array private

Defined in src\core\Entity.ts:454

Available since 1.1.0

Any tags that are on this Entity. This can be used to grab GameObjects or Groups on the whole game which have these particular tags. By default Entitys contain no tags.

_visible

Boolean private

A boolean that indicates whether or not this entity is visible or not. Note that is does not get set to false if the alpha is 0.

Default: true

_willRender

Boolean deprecated private

Defined in src\core\Entity.ts:543

Deprecated: Use _visible instead

Controls whether render is automatically called by the parent.

Default: true

active

Boolean public

Toggles the active state of this Entity. An Entity that is active has its update method called by its parent. This method should be over-ridden to handle specific dom/canvas/webgl implementations.

alpha

Number public

Alpha of this entity. A number between 0 (invisible) and 1 (completely visible).

anchorPointX

Number public

Defined in src\core\Entity.ts:203

Available since 1.1.0

The anchor point on the x-axis. This is just aliased to the rotPointX on the transform object.

anchorPointY

Number public

Defined in src\core\Entity.ts:217

Available since 1.1.0

The anchor point on the y-axis. This is just aliased to the rotPointY on the transform object.

atlas

Kiwi.Textures.TextureAtlas public

The texture atlas that is to be used on this entity.

cellIndex

Number public

Used as a reference to a single Cell in the atlas that is to be rendered.

E.g. If you had a spritesheet with 3 frames/cells and you wanted the second frame to be displayed you would change this value to 1

Default: 0

clock

Kiwi.Time.Clock public

The Clock used to update this all of this Entities components (defaults to the Game MasterClock)

components

Kiwi.ComponentManager public

The Component Manager

dirty

Boolean public

A value used by components to control if the Entity needs re-rendering

exists

Boolean public

Toggles the existence of this Entity. An Entity that no longer exists can be garbage collected or re-allocated in a pool.

game

Game public

The game this Entity belongs to

height

Number public

The height of the entity in pixels, pre-transform.

To obtain the actual height, multiply height by scaleY.

Default: 0

id

String public

A unique identifier for this Entity within the game used internally by the framework. See the name property for a friendly version.

inputEnabled

Boolean deprecated public

Defined in src\core\Entity.ts:577

Deprecated: As of 1.2.3, nothing was found to use this.

Controls if this Entity is input enabled or not (i.e. responds to touch/mouse events) This method should be over-ridden to handle specific game object implementations.

name

String public

A name for this Entity. This is not checked for uniqueness within the Game, but is very useful for debugging

Default: ''

parent

Group public

The group that this entity belongs to/is a child of once added to one. If added onto the state then this is the state.

Sub-properties:

rotation

Number public

Rotation of this Entity. This is just aliased to the transform property.

rotPointX

Number public

The rotation point on the x-axis. This is just aliased to the rotPointX on the transform object.

rotPointY

Number public

The rotation point on the y-axis. This is just aliased to the rotPointY on the transform object.

scale

Number public

Defined in src\core\Entity.ts:153

Available since 1.1.0

Scale both axes of this Entity. This is just aliased to the transform property. This is WRITE-ONLY.

scaleX

Number public

Scale X of this Entity. This is just aliased to the transform property.

scaleY

Number public

Scale Y coordinate of this Entity. This is just aliased to the transform property.

state

State public

The state this Entity belongs to (either the current game state or a persistent world state)

transform

Kiwi.Geom.Transform public

Represents the position, scale, rotation and registration of this Entity.

visible

Boolean public

Set the visibility of this entity. True or False.

Default: true

width

Number public

The width of the entity in pixels, pre-transform.

To obtain the actual width, multiply width by scaleX.

Default: 0

willRender

Boolean deprecated public

Defined in src\core\Entity.ts:553

Deprecated: Use visible instead

Toggles if this Entity will be rendered.

Default: true

worldX

Number public

Defined in src\core\Entity.ts:104

Available since 1.1.0

X coordinate of this Entity in world space; that is, after inheriting parent transforms. This is just aliased to the transform property. Property is READ-ONLY.

worldY

Number public

Defined in src\core\Entity.ts:115

Available since 1.1.0

Y coordinate of this Entity in world space; that is, after inheriting parent transforms. This is just aliased to the transform property. Property is READ-ONLY.

x

Number public

X coordinate of this Entity. This is just aliased to the transform property.

y

Number public

Y coordinate of this Entity. This is just aliased to the transform property.