GameEntity

BGE. GameEntity

Every thing (character, player, object, etc) in the game should extend this class. This class has a number of empty methods that are designed to be overridden in subclasses. For example, override onInput() to handle input event, and onUpdate() to handle updating each frame

Constructor

new GameEntity(game, argsopt) → {dynamic}

Creates a new GameEntity

Parameters:
Name Type Attributes Default Description
game Game

The game engine that this entity is going to be assigned to

args object <optional>
{}

Any extra properties to be added to this entity

Properties:
Name Type Description
name string

Constant - name of this Entity

id string

Constant - Unique Id

enabled boolean

Is this GameEntity enabled

persistent boolean

Does this entity persist across room changes?

pauseable boolean

When the game is paused, does this entity pause too?

zIndex integer

zIndex is used when handling draw order in the game loop - lower zIndex is drawn first

x float

x position of where this entity is in game world

y float

y position of where this entity is in game world

xspeed float

Speed in x/horizontal direction

yspeed float

Speed in y/vertical direction

rotation integer

Rotation of entity - applies to all images

colliders object

The colliders for this entity by name

images object

The array of images to draw for this entity

imagesByName object

Associative array of images by name

tagsList dynamic

Game Entities can be tagged with any number of tags so they can be easily identified (e.g. "enemy", "wall", etc.)

Source:

Methods

addAnimatedImage(imageName, regions, argsopt, insertPositionopt) → {AnimatedImage}

Adds a animated image to be drawn for this entity. Animated images cycle through regions of a bitmap (e.g. spritesheet)

Parameters:
Name Type Attributes Default Description
imageName string

Name of the image

regions object

an array of roRegion of a bitmap to draw

args object <optional>
{}

any extra properties to set (e.g. offset_x, offset_y, rotation, scale_x, scale_y, etc.)

insertPosition integer <optional>
-1

the position/order in the images array where the image should be added (defaults to being added at the end)

Source:

addCircleCollider(colliderName, radius, offset_xopt, offset_yopt, enabledopt) → {object}

Adds a circle collider to this entity

Parameters:
Name Type Attributes Default Description
colliderName string

Name of the collider (only one collider with the same name can be added)

radius float

radius of the circle

offset_x float <optional>
0

horizontal offset from entity position of centre of the circle

offset_y float <optional>
0

vertical offset from entity position of centre of the circle

enabled boolean <optional>
true

is this collider enabled?

Source:

addCollider(collider) → {Collider}

Adds a collider that has already been constructed

Parameters:
Name Type Description
collider Collider

the collider to add (only one collider with the same name can be added)

Source:

addImage(imageName, region, argsopt, insertPositionopt) → {Image}

Adds a basic image (non-animated) to be drawn for this entity

Parameters:
Name Type Attributes Default Description
imageName string

Name of the image

region object

an roRegion of a bitmap to draw

args object <optional>
{}

any extra properties to set (e.g. offset_x, offset_y, rotation, scale_x, scale_y, etc.)

insertPosition integer <optional>
-1

the position/order in the images array where the image should be added (defaults to being added at the end)

Source:

addImageObject(imageName, imageObject, insertPositionopt) → {Drawable}

Adds any Image object to this entity

Parameters:
Name Type Attributes Default Description
imageName string

Name of the image

imageObject Drawable

The image to be added

insertPosition integer <optional>
-1

the position/order in the images array where the image should be added (defaults to being added at the end)

Source:

addInterface(interfaceName) → {void}

TODO: work on Interfaces

Parameters:
Name Type Description
interfaceName string
Source:

addRectangleCollider(colliderName, width, height, offset_xopt, offset_yopt, enabledopt) → {object}

Adds a rectangle collider to this entity

Parameters:
Name Type Attributes Default Description
colliderName string

Name of the collider (only one collider with the same name can be added)

width float

Width of rectangle

height float

Height of rectangle

offset_x float <optional>
0

horizontal offset from entity position of top left point of rectangle

offset_y float <optional>
0

vertical offset from entity position of top left point of rectangle

enabled boolean <optional>
true

is this collider enabled?

Source:

addSprite(bitmap, imageName, spriteSheet, cellWidth, cellHeight, argsopt, insertPositionopt) → {Sprite}

Adds a Sprite to be drawn for this entity. Sprites can have specific animations configured buy choosing series of cells from a sprite sheet

Parameters:
Name Type Attributes Default Description
bitmap object

the bitmap object to use for teh SpriteSheet (e.g response from game.getBitmap("bitmap_name"))

imageName string

Name of the image

spriteSheet object
cellWidth integer

the height in pixels of a dingle cell in the sprite

cellHeight integer

the height in pixels of a dingle cell in the sprite

args object <optional>
{}

any extra properties to set (e.g. offset_x, offset_y, rotation, scale_x, scale_y, etc.)

insertPosition integer <optional>
-1

the position/order in the images array where the image should be added (defaults to being added at the end)

Source:

clearAllColliders() → {void}

Remove all colliders from this entity

Source:

getCollider(colliderName) → {Collider}

Gets a collider based on its name

Parameters:
Name Type Description
colliderName string

The name of the collider to find

Source:

getImage(imageName) → {Drawable}

Gets an image by its name from the lookup table

Parameters:
Name Type Description
imageName string

Name of image to get

Source:

getStaticVariable(staticVariableName) → {dynamic}

TODO: work on statics

Parameters:
Name Type Description
staticVariableName string
Source:

hasInterface(interfaceName) → {boolean}

TODO: work on Interfaces

Parameters:
Name Type Description
interfaceName string
Source:

isValid() → {boolean}

Is this still a valid entity?

Source:

onAudioEvent(msg) → {void}

Method to handle audio events

Parameters:
Name Type Description
msg object

roAudioPlayerEvent

Source:
See:

onChangeRoom(newRoom) → {void}

Method called when the current room changes. This method is only called when the entity is marked as persistant, otherwise entities are destroyed on room changes.

Parameters:
Name Type Description
newRoom Room

The next room

Source:

onCollision(collider, otherCollider, otherEntity) → {void}

Method for processing all collisions

Parameters:
Name Type Description
collider Collider

the collider of this entity that collided

otherCollider Collider

the collider of the other entity in the collision

otherEntity GameEntity

the entity that owns the other collider

Source:

onCreate(args) → {void}

Method to be called when this entity is added to a Game. Override in subclass

Parameters:
Name Type Description
args object
Source:

onDestroy() → {void}

Method called when this entity is destroyed

Source:

onDrawBegin(canvas) → {void}

Method called each frame before drawing any images of this entity

Parameters:
Name Type Description
canvas object

the canvas images will be drawn to

Source:

onDrawEnd(canvas) → {void}

Method called each frame after drawing all images of this entity

Parameters:
Name Type Description
canvas object

the canvas images were drawn to

Source:

onECPInput(data) → {void}

Method to process an External Control Protocol event

Parameters:
Name Type Description
data object
Source:
See:

onECPKeyboard(char) → {void}

Method to process an ECP keyboard event

Parameters:
Name Type Description
char integer
Source:
See:

onGameEvent(eventName, data) → {void}

General purpose event handler for in-game events.

Parameters:
Name Type Description
eventName string

Event name that describes the event type

data object

Any extra data to go along with the event

Source:

onInput(input) → {void}

Method to process input per frame

Parameters:
Name Type Description
input GameInput

GameInput object for the last frame

Source:

onPause() → {void}

Called when the game pauses

Source:

onResume(pauseTimeMs) → {void}

Called when the game unpauses

Parameters:
Name Type Description
pauseTimeMs integer

The number of milliseconds the game was paused

Source:

onUpdate(deltaTime) → {void}

Method for handling any updates based on time since previous frame

Parameters:
Name Type Description
deltaTime float

milliseconds since last frame

Source:

onUrlEvent(msg) → {void}

Called on url event

Parameters:
Name Type Description
msg object

roUrlEvent

Source:
See:

removeCollider(colliderName) → {void}

Removes a collider by its name

Parameters:
Name Type Description
colliderName string

the name of the collider to remove

Source:

removeImage(imageName) → {void}

Removes an image from the entity

Parameters:
Name Type Description
imageName string

Name of image to remove

Source:

setStaticVariable(staticVariableName, staticVariableValue) → {void}

TODO: work on statics

Parameters:
Name Type Description
staticVariableName string
staticVariableValue dynamic
Source: