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
Properties
name(string) — Constant - name of this Entityid(dynamic) — Constant - Unique Idgame(Game)enabled(boolean) — Is this GameEntity enabledpersistent(boolean) — Does this entity persist across room changes?pauseable(boolean) — When the game is paused, does this entity pause too?position(dynamic) — position of where this entity is in game worldvelocity(dynamic) — Speed of this entity, in units/second (not units/frame) - added to position each frame scaled by elapsed timerotation(dynamic) — Rotation of entity - applies to all imagesscale(dynamic) — Scale of entity - applies to all imagescolliders(roAssociativeArray) — The colliders for this entity by namedrawables(dynamic) — The array of drawables to draw for this entitydrawablesByName(roAssociativeArray) — Associative array of drawables by nametagsList(dynamic) — Game Entities can be tagged with any number of tags so they can be easily identified (e.g. "enemy", "wall", etc.)transformationMatrix(dynamic) — The Current Transformation MatrixmotionChecker(MotionChecker)
Constructor
new GameEntity(
game: Game,
gameEngine: Game,
args?: roAssociativeArray,
): GameEntityCreates a new GameEntity
Parameters
game(Game) — The game engine that this entity is going to be assigned togameEngine(Game)args(roAssociativeArray, optional, default: "{}") — Any extra properties to be added to this entity
Instance Methods
isValid(): boolean
Is this still a valid entity?
Returns
boolean
invalidate(): void
Marks this entity as invalid, so it will be cleared/destroyed at the end of the frame
Returns
void
onCreate(args: roAssociativeArray): void
Method to be called when this entity is added to a Game. Override in subclass
Parameters
args(roAssociativeArray)
Returns
void
onUpdate(deltaTime: float): void
Method for handling any updates based on time since previous frame
Parameters
deltaTime(float) — milliseconds since last frame
Returns
void
onCollision(
myCollider: Collider,
otherCollider: Collider,
otherEntity: GameEntity,
): void
Method for processing all collisions
Parameters
myCollider(Collider) — the collider of this entity that collidedotherCollider(Collider) — the collider of the other entity in the collisionotherEntity(GameEntity) — the entity that owns the other collider
Returns
void
onDrawBegin(
Renderer: renderer,
gameRenderer: Renderer,
uiRenderer: Renderer,
): void
Method called each frame before drawing any images of this entity
Parameters
Renderer(renderer) — the Renderer images will be drawn togameRenderer(Renderer)uiRenderer(Renderer)
Returns
void
onDrawEnd(
canvas: Renderer,
gameRenderer: Renderer,
uiRenderer: Renderer,
): void
Method called each frame after drawing all images of this entity
Parameters
Returns
void
onInput(input: GameInput): void
Method to process input per frame
Parameters
input(GameInput) — GameInput object for the last frame
Returns
void
onECPKeyboard(char: integer): void
Method to process an ECP keyboard event
Parameters
char(integer)
Returns
void
onECPInput(data: roInputEvent): void
Method to process an External Control Protocol event
Parameters
data(roInputEvent)
Returns
void
onAudioEvent(msg: roAudioPlayerEvent): void
Method to handle audio events
Parameters
msg(roAudioPlayerEvent) — roAudioPlayerEvent
Returns
void
onPause(): void
Called when the game pauses
Returns
void
onResume(pauseTimeMs: integer): void
Called when the game unpauses
Parameters
pauseTimeMs(integer) — The number of milliseconds the game was paused
Returns
void
onUrlEvent(msg: roUrlEvent): void
Called on url event
Parameters
msg(roUrlEvent) — roUrlEvent
Returns
void
onGameEvent(eventName: string, data: roAssociativeArray): void
General purpose event handler for in-game events.
Parameters
eventName(string) — Event name that describes the event typedata(roAssociativeArray) — Any extra data to go along with the event
Returns
void
onChangeRoom(newRoom: Room): 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
newRoom(Room) — The next room
Returns
void
onDestroy(): void
Method called when this entity is destroyed
Returns
void
addCircleCollider(
colliderName: string,
radius: float,
offset_x?: float,
offset_y?: float,
enabled?: boolean,
): CircleCollider
Adds a circle collider to this entity
Parameters
colliderName(string) — Name of the collider (only one collider with the same name can be added)radius(float) — radius of the circleoffset_x(float, optional, default: 0) — horizontal offset from entity position of centre of the circleoffset_y(float, optional, default: 0) — vertical offset from entity position of centre of the circleenabled(boolean, optional, default: true) — is this collider enabled?
Returns
addRectangleCollider(
colliderName: string,
width: float,
height: float,
offset_x?: float,
offset_y?: float,
enabled?: boolean,
): RectangleCollider
Adds a rectangle collider to this entity
Parameters
colliderName(string) — Name of the collider (only one collider with the same name can be added)width(float) — Width of rectangleheight(float) — Height of rectangleoffset_x(float, optional, default: 0) — horizontal offset from entity position of left edge of rectangleoffset_y(float, optional, default: 0) — vertical offset from entity position of bottom edge of rectangle (top edge is at offset_y - height)enabled(boolean, optional, default: true) — is this collider enabled?
Returns
addCollider(colliderToAdd: Collider): Collider
Adds a collider that has already been constructed
Parameters
colliderToAdd(Collider) — the collider to add (only one collider with the same name can be added)
Returns
getCollider(colliderName: string): Collider
Gets a collider based on its name
Parameters
colliderName(string) — The name of the collider to find
Returns
removeCollider(colliderName: string): void
Removes a collider by its name
Parameters
colliderName(string) — the name of the collider to remove
Returns
void
clearAllColliders(): void
Remove all colliders from this entity
Returns
void
addImage(
regionName?: string,
imageName: string,
region: roRegion,
args?: roAssociativeArray,
insertPosition?: integer,
): Image
Adds a basic image (non-animated) to be drawn for this entity
Parameters
regionName(string, optional, default: "\"\"") — an optional unique name for the region, used for caching image dataimageName(string) — Name of the imageregion(roRegion) — anroRegionof a bitmap to drawargs(roAssociativeArray, optional, default: "{}") — any extra properties to set (e.g. offset_x, offset_y, rotation, scale_x, scale_y, etc.)insertPosition(integer, optional, default: -1) — the position/order in the images array where the image should be added (defaults to being added at the end)
Returns
addAnimatedImage(
imageName: string,
regions: Array.<roRegion>,
args?: roAssociativeArray,
insertPosition?: integer,
): AnimatedImage
Adds a animated image to be drawn for this entity. Animated images cycle through regions of a bitmap (e.g. spritesheet)
Parameters
imageName(string) — Name of the imageregions(Array.<roRegion>) — an array ofroRegionof a bitmap to drawargs(roAssociativeArray, optional, default: "{}") — any extra properties to set (e.g. offset_x, offset_y, rotation, scale_x, scale_y, etc.)insertPosition(integer, optional, default: -1) — the position/order in the images array where the image should be added (defaults to being added at the end)
Returns
addSprite(
bitmap: roBitmap,
imageName: string,
spriteSheet: roBitmap,
cellWidth: integer,
cellHeight: integer,
args?: roAssociativeArray,
insertPosition?: integer,
): 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
bitmap(roBitmap) — the bitmap object to use for teh SpriteSheet (e.g response from game.getBitmap("bitmap_name"))imageName(string) — Name of the imagespriteSheet(roBitmap)cellWidth(integer) — the height in pixels of a dingle cell in the spritecellHeight(integer) — the height in pixels of a dingle cell in the spriteargs(roAssociativeArray, optional, default: "{}") — any extra properties to set (e.g. offset_x, offset_y, rotation, scale_x, scale_y, etc.)insertPosition(integer, optional, default: -1) — the position/order in the images array where the image should be added (defaults to being added at the end)
Returns
addRectangle(
rectangleName: string,
width: float,
height: float,
args?: roAssociativeArray,
insertPosition?: integer,
): DrawableRectangle
Adds a rectangle to be drawn for this entity. The rectangle's top left corner sits at the entity's position (plus the drawable's own offset), and it extends width to the right and height downwards in world space.
Parameters
rectangleName(string) — Name of the rectanglewidth(float) — width of the rectangle in world unitsheight(float) — height of the rectangle in world unitsargs(roAssociativeArray, optional, default: "{}") — any extra properties to set (e.g. color, outlineRGBA, outlineWidth, filled, offset, rotation, scale, drawMode)insertPosition(integer, optional, default: -1) — the position/order in the drawables array where the rectangle should be added (defaults to being added at the end)
Returns
addDrawable(
imageName: string,
drawableObject: Drawable,
insertPosition?: integer,
): Drawable
Adds any Drawable/Image object to this entity
Parameters
imageName(string) — Name of the imagedrawableObject(Drawable) — The image to be addedinsertPosition(integer, optional, default: -1) — the position/order in the images array where the image should be added (defaults to being added at the end)
Returns
getDrawable(imageName: string, drawableName: string): Drawable
Gets a drawable by its name from the lookup table
Parameters
imageName(string) — Name of drawable to getdrawableName(string)
Returns
removeDrawable(drawableName: string): void
Removes a drawable from the entity
Parameters
drawableName(string) — Name of drawable to remove
Returns
void
updateTransformationMatrix(): void
Returns
void
movedLastFrame(): boolean
Returns
boolean
getStaticVariable(staticVariableName: string): dynamic
TODO: work on statics
Parameters
staticVariableName(string)
Returns
dynamic
setStaticVariable(
staticVariableName: string,
staticVariableValue: dynamic,
): void
TODO: work on statics
Parameters
staticVariableName(string)staticVariableValue(dynamic)
Returns
void
addInterface(interfaceName: string): void
TODO: work on Interfaces
Parameters
interfaceName(string)
Returns
void
hasInterface(interfaceName: string): boolean
TODO: work on Interfaces
Parameters
interfaceName(string)
Returns
boolean
debugDraw(
renderObj: Renderer,
drawAxes?: boolean,
drawName?: boolean,
): void
Draws the entity's axes and/or its name
Parameters
renderObj(Renderer)drawAxes(boolean, optional, default: false)drawName(boolean, optional, default: false)
Returns
void