API Docs for: 1.0.1
Show:

Kiwi.GameObjects.Sprite Class

Extends Kiwi.Entity
Module: GameObjects
Parent Module: Kiwi

A Sprite is a general purpose GameObject that contains majority of the functionality that is needed/would be wanted and as such should be used only when you are wanting a GameObject with a lot of interaction. When creating a Sprite you pass to it as TextureAtlas (for the image you want to render), now if that Texture Atlas isn't a SINGLE_IMAGE then the Sprite will have an AnimationManager Component to handle any SpriteSheet animations you need.

Constructor

Kiwi.GameObjects.Sprite

(
  • state
  • atlas
  • [x=0]
  • [y=0]
  • [enableInput=false]
)
Sprite

Parameters:

  • state Kiwi.State

    The state that this sprite belongs to

  • atlas Kiwi.Textures.TextureAtlas

    The texture you want to apply to this entity

  • [x=0] Number optional

    The sprites initial coordinates on the x axis.

  • [y=0] Number optional

    The sprites initial coordinates on the y axis.

  • [enableInput=false] Boolean optional

    If the input component should be enabled or not.

Returns:

Sprite:

Methods

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.

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.

objType

() String public

Inherited from Kiwi.Entity but overwritten in src\gameobjects\Sprite.ts:69

Returns the type of object that this is.

Returns:

String:

render

(
  • camera
)
public

Inherited from Kiwi.Entity but overwritten in src\gameobjects\Sprite.ts:132

Renders the GameObject using Canvas.

Parameters:

renderGL

(
  • gl
  • camera
  • params
)
public

Inherited from Kiwi.Entity but overwritten in src\gameobjects\Sprite.ts:166

Renders the GameObject using WebGL.

Parameters:

  • gl WebGLRenderingContext
  • camera Kiwi.Camera
  • params Object

update

() public

Inherited from Kiwi.Entity but overwritten in src\gameobjects\Sprite.ts:113

Called by parent when its update loop gets executed.

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.

_exists

Boolean private

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

_inputEnabled

Boolean private

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

_isAnimated

Boolean private

Indicates whether or not this sprite is animated or not. This sprite will not be animated if the texture used is a SINGLE_IMAGE.

_parent

Kiwi.Group private

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

_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 private

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

animation

Kiwi.Components.AnimationManager public

The animation component that allows you to create a animation with spritesheets/texture atlas's. Note: If the atlas that was added is of type Kiwi.Textures.TextureAtlas.SINGLE_IMAGE then no animation component will be created.

atlas

Kiwi.Textures.TextureAtlas public

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

box

Kiwi.Components.Box public

The box component that controls the bounding box around this Game Object

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 private

Inherited from Kiwi.Entity but overwritten in src\core\Entity.ts:445

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.

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.

input

Kiwi.Components.Input public

The Input component controls the user interaction with this Game Object

inputEnabled

Boolean public

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.

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.

visibility

Boolean public

Set the visiblity of this entity. True or False.

Default: true

width

Number public

The width of the entity in pixels.

Default: 0

willRender

Boolean public

Toggles if this Entity will be rendered.

Default: true

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.