GameSession
Extends: BGE.GameEntity
Score, lives and the ready / playing / paused / over / levelComplete flow of an arcade game, as an entity. It keeps the numbers and the state, and posts a game event (stateEventName) when the state changes. Your game keeps its own rules and screens: it calls addScore(), loseLife(), start(), gameOver() and completeLevel() when its own events happen.
Opt in to more: prompts shows a centered "Press OK To Play" / "Game Over!" label (the text is yours to change), startButton/startAction start the game for you, and persistHighScore() keeps the best score in the registry. Subclass and override onStateChanged(), onGameOver() or onLevelComplete() for anything else.
Properties
score(integer)lives(integer) — Lives left. 0 when lives aren't used.startLives(integer) — Lives a new game starts with. 0 means lives aren't used.highScore(integer) — The best score from the registry (see persistHighScore()), updated when a game ends.state(BGE.GameSessionState)previousState(BGE.GameSessionState)stateEventName(string) — Game event posted with a GameSessionStateEvent when the state changes. "" for none.prompts(boolean) — Show the stock prompt label? Its text comes from the *Prompt fields below.readyPrompt(string)overPrompt(string)pausedPrompt(string)levelCompletePrompt(string)promptLabel(BGE.UI.Label) — The prompt: a centered label in the current scene's UI. Restyle or move it freely.startButton(string) — Remote button that starts the game from ready or over. "" for none.startAction(string) — ControlMap action that starts the game from ready or over. "" for none.profile(BGE.SaveProfile) — Set by persistHighScore().highScoreTable(string)
Example
session = new BGE.GameSession(game, {lives: 3, prompts: true, startButton: "ok"})
session.persistHighScore("my-game")
game.addEntity(session)
' When something scores:
session.addScore(10)
' When the player's hit:
if session.loseLife()
' that was the last life - the session is now over
end ifConstructor
new GameSession(
game: BGE.Game,
options?: BGE.GameSessionOptions,
): GameSessionParameters
game(BGE.Game)options(BGE.GameSessionOptions, optional, default: "{}")
Instance Methods
isPlaying(): boolean
Returns
boolean— is the game being played (not ready, paused or ended)?
hasEnded(): boolean
Returns
boolean— is the game over, or the level complete?
usesLives(): boolean
Does this session count lives?
Returns
boolean
start(): boolean
Starts playing. From game over it's a new game: the score and lives are reset first. Does nothing while playing or paused.
Returns
boolean— whether it started
reset(): void
Back to ready with a fresh score and lives.
Returns
void
pause(): boolean
Pauses a game that's playing. Only the state: pausing the game itself is up to you (e.g. BGE.PauseMenu).
Returns
boolean— whether it paused
resume(): boolean
Carries on after pause().
Returns
boolean— whether it resumed
gameOver(): boolean
Ends the game: records a high score (see persistHighScore()) and calls onGameOver().
Returns
boolean— false if it was already over
completeLevel(): boolean
Marks the level won and calls onLevelComplete(). Ignored once the game's over.
Returns
boolean— whether the state changed
addScore(points?: integer): void
Adds points. Ignored once the game's over or the level's complete.
Parameters
points(integer, optional, default: 1)
Returns
void
loseLife(count?: integer): boolean
Takes lives; the game's over when they run out. Does nothing when lives aren't used (startLives is 0), or once the game's over or the level's complete.
Parameters
count(integer, optional, default: 1)
Returns
boolean— true if this ended the game
addLife(count?: integer): void
Adds lives.
Parameters
count(integer, optional, default: 1)
Returns
void
setState(newState: BGE.GameSessionState): boolean
Moves to a state: records a game-over high score, calls the hooks, posts stateEventName and updates the prompt. Prefer start(), gameOver() etc., which check the move makes sense.
Parameters
newState(BGE.GameSessionState)
Returns
boolean— false if it was already in that state
persistHighScore(section: string, table?: string): void
Keeps the best score in the registry: reads it into highScore now, and records the score whenever the game's over. Uses BGE.SaveProfile, so it shares that profile's registry key with anything else you keep there.
Parameters
section(string) — registry section, e.g. your game's idtable(string, optional, default: "\"highScore\"") — the profile value it's kept under
Returns
void
recordHighScore(): boolean
Saves the score if it's a new best (once persistHighScore() is set up), and updates highScore. Called for you on game over.
Returns
boolean— true if it's a new best
onStateChanged(
previousState: BGE.GameSessionState,
newState: BGE.GameSessionState,
): void
Called on every state change, before the event is posted. Does nothing by default.
Parameters
previousState(BGE.GameSessionState)newState(BGE.GameSessionState)
Returns
void
onGameOver(): void
Called when the game's over, after onStateChanged(). Does nothing by default.
Returns
void
onLevelComplete(): void
Called when the level's complete, after onStateChanged(). Does nothing by default.
Returns
void
getPromptText(forState: BGE.GameSessionState): string
The prompt text for a state ("" for none). Override to make your own.
Parameters
forState(BGE.GameSessionState)
Returns
string
updatePrompt(): void
Shows the current state's prompt, or hides it when prompts is off. Call it after changing prompts or a prompt's text.
Returns
void
onCreate(args: roAssociativeArray): void
Parameters
args(roAssociativeArray)
Returns
void
onUpdate(deltaTime: float): void
Parameters
deltaTime(float)
Returns
void
onChangeScene(newScene: BGE.GameScene): void
Parameters
newScene(BGE.GameScene)
Returns
void
onInput(input: BGE.GameInput): void
Parameters
input(BGE.GameInput)
Returns
void
onControls(controls: BGE.Controller.ControlMap): void
Parameters
controls(BGE.Controller.ControlMap)
Returns
void
isValid(): boolean
Inherited from BGE.GameEntity#isValid
Overrides: BGE.GameEntity#isValid
Is this still a valid entity?
Returns
boolean
getVisibility(): BGE.VisibilityState
Inherited from BGE.GameEntity#getVisibility
Overrides: BGE.GameEntity#getVisibility
The most visible state among this entity's drawables as of the last frame, in the order visible > occluded > offCamera > unknown: visible if any was drawn, occluded if something in front hid it, offCamera if the camera couldn't see it. unknown for an entity with no drawables, or before its first frame.
Returns
isOnScreen(): boolean
Inherited from BGE.GameEntity#isOnScreen
Overrides: BGE.GameEntity#isOnScreen
Whether this entity might be seen: true when it is visible or unknown (no drawables, or not drawn yet), false when it is occluded or off camera. A purely logical entity (a spawner, a game-state controller) is never treated as off-screen.
This is a signal only - nothing in the engine uses it to skip an entity's own onUpdate()/collision checks automatically, since a hidden entity can still be relevant to gameplay (e.g. approaching from off-screen). It's meant for game code that wants to opt in to skipping its own expensive, purely-visual per-frame work for an entity that isn't currently visible. See issue #75.
Returns
boolean
addLight(light: BGE.Light): void
Inherited from BGE.GameEntity#addLight
Overrides: BGE.GameEntity#addLight
Adds a light to the game (see Game.addLight()) that belongs to this entity: it's removed when the entity is destroyed or invalidated, or for a scene, when the game leaves the scene (after onDestroy()). A light added with game.addLight() stays until removed.
Parameters
light(BGE.Light)
Returns
void
Example
m.addLight(new BGE.PointLight(m.position, 300, &hFF9440, 1.5))removeLight(light: BGE.Light): boolean
Inherited from BGE.GameEntity#removeLight
Overrides: BGE.GameEntity#removeLight
Removes a light, from the game and from this entity's.
Parameters
light(BGE.Light)
Returns
boolean— true if the game had it
removeLights(): void
Inherited from BGE.GameEntity#removeLights
Overrides: BGE.GameEntity#removeLights
Removes every light added with addLight() from the game. The game calls it when the entity is invalidated, and for a scene, when it's left.
Returns
void
getLights(): Array.<BGE.Light>
Inherited from BGE.GameEntity#getLights
Overrides: BGE.GameEntity#getLights
The lights added with addLight() that haven't been removed (a copy).
Returns
Array.<BGE.Light>
invalidate(): void
Inherited from BGE.GameEntity#invalidate
Overrides: BGE.GameEntity#invalidate
Marks this entity as invalid, so it will be cleared/destroyed at the end of the frame. Its drawables and the lights added with addLight() are removed at once.
Returns
void
invalidateAfter(delayMs: integer): void
Inherited from BGE.GameEntity#invalidateAfter
Overrides: BGE.GameEntity#invalidateAfter
Marks this entity as dying: it stays fully alive, valid, and processed normally (still updates, still draws, still collides) for delayMs milliseconds, then invalidate() is called automatically. Use this instead of calling invalidate() directly when an entity needs to trigger a one-shot effect (e.g. a particle burst) that should have a chance to actually render before the entity disappears - invalidate() removes all of this entity's drawables from the scene immediately, which would cut off that effect on its very first frame.
Sets isDying = true immediately, so other game code (e.g. a collision handler) can check it to avoid re-triggering logic on an entity that's already in its death sequence. Colliders are NOT removed during the grace period - a dying entity can still register collisions until it's actually invalidated, so guard on isDying at the very top of onCollision() (before any score/sound/effect side effect) to avoid double-firing.
Parameters
delayMs(integer) — how long to wait, in milliseconds, before this entity is actually invalidated
Returns
void
checkDyingTimeout(): void
Inherited from BGE.GameEntity#checkDyingTimeout
Overrides: BGE.GameEntity#checkDyingTimeout
Called once per frame (from Game's entity-processing loop) for every valid entity, regardless of whether it overrides onUpdate() - checks whether an invalidateAfter() grace period has elapsed and, if so, calls the real invalidate(). A no-op for an entity that isn't dying.
Returns
void
tickDrawableFlashes(dt: float): void
Inherited from BGE.GameEntity#tickDrawableFlashes
Overrides: BGE.GameEntity#tickDrawableFlashes
Advances every drawable's flash() by dt. The game calls this before onUpdate() while any drawable is flashing.
Parameters
dt(float) — seconds
Returns
void
onCreate(args: roAssociativeArray): void
Inherited from BGE.GameSession#onCreate
Overrides: BGE.GameEntity#onCreate
Method to be called when this entity is added to a Game. Override in subclass
Parameters
args(roAssociativeArray)
Returns
void
onUpdate(deltaTime: float): void
Inherited from BGE.GameSession#onUpdate
Overrides: BGE.GameEntity#onUpdate
Method for handling any updates based on time since previous frame
Parameters
deltaTime(float)
Returns
void
onCollision(
myCollider: Collider,
otherCollider: Collider,
otherEntity: GameEntity,
): void
Inherited from BGE.GameEntity#onCollision
Overrides: BGE.GameEntity#onCollision
Called every frame, for each pair of colliders that overlap that frame - not just when an overlap starts (use onCollisionEnter() for that).
Colliders that only touch edge to edge don't overlap, so they don't collide. If you resolve a collision by moving this entity so it sits exactly against the other collider (e.g. snapping a player's feet to the top of the ground), it won't collide again next frame unless it moves back into it. So don't reset a "grounded"-style flag every frame and wait for onCollision() to set it again. Either keep applying gravity while grounded, so the player sinks slightly back into the ground each frame, or check for ground some other way, e.g. a thin feet collider that reaches a pixel below the player.
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
onCollisionEnter(
myCollider: Collider,
otherCollider: Collider,
otherEntity: GameEntity,
): void
Inherited from BGE.GameEntity#onCollisionEnter
Overrides: BGE.GameEntity#onCollisionEnter
Called once when one of this entity's colliders starts overlapping another collider, just before that frame's onCollision(). Use it for one-shot reactions - a trigger zone, a pickup, taking a hit - instead of tracking "was I already touching this?" yourself.
Parameters
myCollider(Collider) — the collider of this entity that started collidingotherCollider(Collider) — the collider of the other entityotherEntity(GameEntity) — the entity that owns the other collider
Returns
void
onCollisionExit(
myCollider: Collider,
otherCollider: Collider,
otherEntity: GameEntity,
): void
Inherited from BGE.GameEntity#onCollisionExit
Overrides: BGE.GameEntity#onCollisionExit
Called once when one of this entity's colliders stops overlapping a collider it overlapped last frame - including when the other entity was destroyed or changed scene, in which case otherCollider and otherEntity are invalid. Also called for every current overlap when myCollider is disabled.
Parameters
myCollider(Collider) — the collider of this entity that stopped collidingotherCollider(Collider) — the collider of the other entity, or invalid if it's goneotherEntity(GameEntity) — the entity that owns the other collider, or invalid if it's gone
Returns
void
onDrawBegin(
Renderer: renderer,
gameRenderer: Renderer,
uiRenderer: Renderer,
): void
Inherited from BGE.GameEntity#onDrawBegin
Overrides: BGE.GameEntity#onDrawBegin
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
Inherited from BGE.GameEntity#onDrawEnd
Overrides: BGE.GameEntity#onDrawEnd
Method called each frame after drawing all images of this entity
Parameters
canvas(Renderer) — the Renderer images were drawn togameRenderer(Renderer)uiRenderer(Renderer)
Returns
void
onInput(input: BGE.GameInput): void
Inherited from BGE.GameSession#onInput
Overrides: BGE.GameEntity#onInput
Method to process input per frame
Parameters
input(BGE.GameInput)
Returns
void
onControls(controls: BGE.Controller.ControlMap): void
Inherited from BGE.GameSession#onControls
Overrides: BGE.GameEntity#onControls
Called once per frame, before onUpdate(), with the game's ControlMap - the same object as m.game.controls, just without the boilerplate of reaching through m.game each frame.
IMPORTANT: only called when the game has bound at least one action/axis via ControlMap.bindAction()/bindAxis() (ControlMap.hasBindings()). A game that never binds anything never gets this callback at all - not with an empty ControlMap, not with an error, just silently never called. This preserves ControlMap's zero-cost guarantee: binding nothing costs nothing, including this dispatch. If your entity overrides onControls() but never sees it fire, check that something in the game calls bindAction/bindAxis.
Parameters
controls(BGE.Controller.ControlMap)
Returns
void
onECPKeyboard(char: integer): void
Inherited from BGE.GameEntity#onECPKeyboard
Overrides: BGE.GameEntity#onECPKeyboard
Method to process an ECP keyboard event
Parameters
char(integer)
Returns
void
onECPInput(data: roInputEvent): void
Inherited from BGE.GameEntity#onECPInput
Overrides: BGE.GameEntity#onECPInput
Method to process an External Control Protocol event
Parameters
data(roInputEvent)
Returns
void
onAudioEvent(msg: roAudioPlayerEvent): void
Inherited from BGE.GameEntity#onAudioEvent
Overrides: BGE.GameEntity#onAudioEvent
Method to handle audio events
Parameters
msg(roAudioPlayerEvent) — roAudioPlayerEvent
Returns
void
onPause(): void
Inherited from BGE.GameEntity#onPause
Overrides: BGE.GameEntity#onPause
Called when the game pauses
Returns
void
onResume(pauseTimeMs: integer): void
Inherited from BGE.GameEntity#onResume
Overrides: BGE.GameEntity#onResume
Called when the game unpauses
Parameters
pauseTimeMs(integer) — The number of milliseconds the game was paused
Returns
void
onUrlEvent(msg: roUrlEvent): void
Inherited from BGE.GameEntity#onUrlEvent
Overrides: BGE.GameEntity#onUrlEvent
Called on url event
Parameters
msg(roUrlEvent) — roUrlEvent
Returns
void
onGameEvent(eventName: string, data: roAssociativeArray): void
Inherited from BGE.GameEntity#onGameEvent
Overrides: BGE.GameEntity#onGameEvent
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
onQualityChanged(level: integer): void
Inherited from BGE.GameEntity#onQualityChanged
Overrides: BGE.GameEntity#onQualityChanged
Called when the game's render quality level changes (see Game.setQualityLevel() and Game.enableAdaptiveQuality()). Override it to scale your own content with quality, e.g. particle counts or effects.
Parameters
level(integer) — the newBGE.RenderQualityLevel
Returns
void
onChangeScene(newScene: BGE.GameScene): void
Inherited from BGE.GameSession#onChangeScene
Overrides: BGE.GameEntity#onChangeScene
Called on every entity added with Game.addEntity(), and on the outgoing scene, whenever a Game.changeScene()/resetScene() takes effect - just before non-persistent entities are destroyed. Override it to save state or clean up.
Parameters
newScene(BGE.GameScene)
Returns
void
onDestroy(): void
Inherited from BGE.GameEntity#onDestroy
Overrides: BGE.GameEntity#onDestroy
Called when this entity is destroyed with Game.destroyEntity(). A scene gets it when it's left (changed away from or reset), just after onChangeScene() - the scene object itself is kept and reused, so onLoad()/onCreate() run again if it's entered again. A non-persistent entity removed by a scene change gets only onChangeScene(), not this.
Returns
void
addCircleCollider(
colliderName: string,
radius: float,
offset_x?: float,
offset_y?: float,
enabled?: boolean,
): CircleCollider
Inherited from BGE.GameEntity#addCircleCollider
Overrides: BGE.GameEntity#addCircleCollider
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
Inherited from BGE.GameEntity#addRectangleCollider
Overrides: BGE.GameEntity#addRectangleCollider
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 top edge of rectangle (world +y is up, so the bottom edge is at offset_y - height)enabled(boolean, optional, default: true) — is this collider enabled?
Returns
addSphereCollider3d(
colliderName: string,
radius: float,
offset_x?: float,
offset_y?: float,
offset_z?: float,
enabled?: boolean,
): SphereCollider3d
Inherited from BGE.GameEntity#addSphereCollider3d
Overrides: BGE.GameEntity#addSphereCollider3d
Adds a sphere collider to this entity, for true 3D overlap detection (not just an XY-space projection) - see BGE.SphereCollider3d.
Parameters
colliderName(string) — Name of the collider (only one collider with the same name can be added)radius(float) — radius of the sphereoffset_x(float, optional, default: 0) — horizontal offset from entity position of centre of the sphereoffset_y(float, optional, default: 0) — vertical offset from entity position of centre of the sphereoffset_z(float, optional, default: 0) — depth offset from entity position of centre of the sphereenabled(boolean, optional, default: true) — is this collider enabled?
Returns
addBoxCollider3d(
colliderName: string,
width: float,
height: float,
depth: float,
offset_x?: float,
offset_y?: float,
offset_z?: float,
enabled?: boolean,
): BoxCollider3d
Inherited from BGE.GameEntity#addBoxCollider3d
Overrides: BGE.GameEntity#addBoxCollider3d
Adds a box collider to this entity, for true 3D overlap detection - see BGE.BoxCollider3d. Note offset is the box's CENTER, unlike addRectangleCollider()'s corner-based offset.
Parameters
colliderName(string) — Name of the collider (only one collider with the same name can be added)width(float) — width of the box (x axis)height(float) — height of the box (y axis)depth(float) — depth of the box (z axis)offset_x(float, optional, default: 0) — horizontal offset from entity position of the box's centeroffset_y(float, optional, default: 0) — vertical offset from entity position of the box's centeroffset_z(float, optional, default: 0) — depth offset from entity position of the box's centerenabled(boolean, optional, default: true) — is this collider enabled?
Returns
addCollider(colliderToAdd: Collider): Collider
Inherited from BGE.GameEntity#addCollider
Overrides: BGE.GameEntity#addCollider
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
Inherited from BGE.GameEntity#getCollider
Overrides: BGE.GameEntity#getCollider
Gets a collider based on its name
Parameters
colliderName(string) — The name of the collider to find
Returns
removeCollider(colliderName: string): void
Inherited from BGE.GameEntity#removeCollider
Overrides: BGE.GameEntity#removeCollider
Removes a collider by its name
Parameters
colliderName(string) — the name of the collider to remove
Returns
void
clearAllColliders(): void
Inherited from BGE.GameEntity#clearAllColliders
Overrides: BGE.GameEntity#clearAllColliders
Remove all colliders from this entity
Returns
void
addImage(
regionName?: string,
imageName: string,
region: roRegion,
args?: roAssociativeArray,
insertPosition?: integer,
): Image
Inherited from BGE.GameEntity#addImage
Overrides: BGE.GameEntity#addImage
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
Inherited from BGE.GameEntity#addAnimatedImage
Overrides: BGE.GameEntity#addAnimatedImage
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(
imageName: string,
spriteSheet: roBitmap | Array.<roBitmap>,
cellWidth: integer,
cellHeight: integer,
args?: roAssociativeArray,
insertPosition?: integer,
): Sprite
Inherited from BGE.GameEntity#addSprite
Overrides: BGE.GameEntity#addSprite
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
imageName(string) — Name of the imagespriteSheet(roBitmap | Array.<roBitmap>) — the sprite sheet bitmap (e.g response from game.getBitmap("bitmap_name")), or several with the same cell size, numbered across in ordercellWidth(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
addOrientedSprite(
imageName: string,
spriteSheet: roBitmap | Array.<roBitmap> | BGE.SpriteFrames,
cellWidth: integer,
cellHeight: integer,
numAngles?: integer,
numElevationBands?: integer,
args?: roAssociativeArray,
insertPosition?: integer,
): DrawableOrientedSprite
Inherited from BGE.GameEntity#addOrientedSprite
Overrides: BGE.GameEntity#addOrientedSprite
Adds a DrawableOrientedSprite to be drawn for this entity - a Sprite that swaps which named animation is active based on the angle between the camera and this entity, faking a full-3D Doom/Duke3D-style billboard sprite. See docs/drawables-and-scene-objects.md for a full walkthrough.
Parameters
imageName(string) — Name of the imagespriteSheet(roBitmap | Array.<roBitmap> | BGE.SpriteFrames) — Sprite sheet to pick cells from, several with the same cell size (numbered across in order), or a BGE.SpriteFrames (packed frames, or shared regions; see Game.getSpriteFrames())cellWidth(integer) — Width of each animation cell in pixelscellHeight(integer) — Height of each animation cell in pixelsnumAngles(integer, optional, default: 8) — Number of horizontal (azimuth) view bucketsnumElevationBands(integer, optional, default: 1) — Number of vertical (elevation) view bandsargs(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) — position among this entity's other drawables to insert at (-1 appends)
Returns
addRectangle(
rectangleName: string,
width: float,
height: float,
args?: roAssociativeArray,
insertPosition?: integer,
): DrawableRectangle
Inherited from BGE.GameEntity#addRectangle
Overrides: BGE.GameEntity#addRectangle
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
addCircle(
circleName: string,
radius: float,
args?: roAssociativeArray,
insertPosition?: integer,
): DrawableCircle
Inherited from BGE.GameEntity#addCircle
Overrides: BGE.GameEntity#addCircle
Adds a filled circle to be drawn for this entity, via the renderer's shared circle texture. The circle's top left (of its bounding square) sits at the entity's position (plus the drawable's own offset), extending radius * 2 right and down in world space - like DrawableRectangle, it foreshortens into an ellipse in the oriented 3D draw modes. Use addSphere() instead for a circle that never does this.
Parameters
circleName(string) — Name of the circleradius(float) — radius of the circle in world unitsargs(roAssociativeArray, optional, default: "{}") — any extra properties to set (e.g. color, outlineRGBA, outlineWidth, outlineSegments, offset, rotation, scale, drawMode)insertPosition(integer, optional, default: -1) — the position/order in the drawables array where the circle should be added (defaults to being added at the end)
Returns
addSphere(
sphereName: string,
radius: float,
args?: roAssociativeArray,
insertPosition?: integer,
): DrawableSphere
Inherited from BGE.GameEntity#addSphere
Overrides: BGE.GameEntity#addSphere
Adds a filled circle that always renders as an undistorted circle regardless of camera angle - because a sphere looks the same from every direction. See DrawableSphere.
Parameters
sphereName(string) — Name of the sphereradius(float) — radius of the sphere in world unitsargs(roAssociativeArray, optional, default: "{}") — any extra properties to set (e.g. color, outlineRGBA, outlineWidth, outlineSegments, offset, scale)insertPosition(integer, optional, default: -1) — the position/order in the drawables array where the sphere should be added (defaults to being added at the end)
Returns
addParticles(
particlesName: string,
shape: BGE.ParticleShape,
args?: roAssociativeArray,
insertPosition?: integer,
): DrawableParticles
Inherited from BGE.GameEntity#addParticles
Overrides: BGE.GameEntity#addParticles
Adds a particle emitter to be drawn for this entity. See DrawableParticles for the full set of configurable behavior (spawnRate, lifetime, velocity/spread, acceleration, color/alpha/size-over-lifetime, maxParticles) and its start()/stop()/ burst() control API.
Parameters
particlesName(string) — Name of the particle emitter drawableshape(BGE.ParticleShape) — see DrawableParticles.shapeargs(roAssociativeArray, optional, default: "{}") — any extra properties to set (e.g. spawnRate, lifetime, velocity, acceleration, startColor, endColor, startAlpha, endAlpha, startSize, endSize, sizeInWorldUnits, maxParticles)insertPosition(integer, optional, default: -1) — the position/order in the drawables array where the emitter should be added (defaults to being added at the end)
Returns
addDrawable(
imageName: string,
drawableObject: Drawable,
insertPosition?: integer,
): Drawable
Inherited from BGE.GameEntity#addDrawable
Overrides: BGE.GameEntity#addDrawable
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
Inherited from BGE.GameEntity#getDrawable
Overrides: BGE.GameEntity#getDrawable
Gets a drawable by its name from the lookup table
Parameters
imageName(string) — Name of drawable to getdrawableName(string)
Returns
removeDrawable(drawableName: string): void
Inherited from BGE.GameEntity#removeDrawable
Overrides: BGE.GameEntity#removeDrawable
Removes a drawable from the entity
Parameters
drawableName(string) — Name of drawable to remove
Returns
void
updateTransformationMatrix(): void
Inherited from BGE.GameEntity#updateTransformationMatrix
Overrides: BGE.GameEntity#updateTransformationMatrix
Returns
void
movedLastFrame(): boolean
Inherited from BGE.GameEntity#movedLastFrame
Overrides: BGE.GameEntity#movedLastFrame
Returns
boolean
getStaticVariable(staticVariableName: string): dynamic
Inherited from BGE.GameEntity#getStaticVariable
Overrides: BGE.GameEntity#getStaticVariable
TODO: work on statics
Parameters
staticVariableName(string)
Returns
dynamic
setStaticVariable(
staticVariableName: string,
staticVariableValue: dynamic,
): void
Inherited from BGE.GameEntity#setStaticVariable
Overrides: BGE.GameEntity#setStaticVariable
TODO: work on statics
Parameters
staticVariableName(string)staticVariableValue(dynamic)
Returns
void
addInterface(interfaceName: string): void
Inherited from BGE.GameEntity#addInterface
Overrides: BGE.GameEntity#addInterface
TODO: work on Interfaces
Parameters
interfaceName(string)
Returns
void
hasInterface(interfaceName: string): boolean
Inherited from BGE.GameEntity#hasInterface
Overrides: BGE.GameEntity#hasInterface
TODO: work on Interfaces
Parameters
interfaceName(string)
Returns
boolean
debugDraw(
renderObj: Renderer,
drawAxes?: boolean,
drawName?: boolean,
): void
Inherited from BGE.GameEntity#debugDraw
Overrides: BGE.GameEntity#debugDraw
Draws the entity's axes and/or its name
Parameters
renderObj(Renderer)drawAxes(boolean, optional, default: false)drawName(boolean, optional, default: false)
Returns
void
onCreate(args: roAssociativeArray): void
Inherited from BGE.GameSession#onCreate
Overrides: BGE.GameEntity#onCreate
Method to be called when this entity is added to a Game. Override in subclass
Parameters
args(roAssociativeArray)
Returns
void
onUpdate(deltaTime: float): void
Inherited from BGE.GameSession#onUpdate
Overrides: BGE.GameEntity#onUpdate
Method for handling any updates based on time since previous frame
Parameters
deltaTime(float)
Returns
void
onInput(input: BGE.GameInput): void
Inherited from BGE.GameSession#onInput
Overrides: BGE.GameEntity#onInput
Method to process input per frame
Parameters
input(BGE.GameInput)
Returns
void
onControls(controls: BGE.Controller.ControlMap): void
Inherited from BGE.GameSession#onControls
Overrides: BGE.GameEntity#onControls
Called once per frame, before onUpdate(), with the game's ControlMap - the same object as m.game.controls, just without the boilerplate of reaching through m.game each frame.
IMPORTANT: only called when the game has bound at least one action/axis via ControlMap.bindAction()/bindAxis() (ControlMap.hasBindings()). A game that never binds anything never gets this callback at all - not with an empty ControlMap, not with an error, just silently never called. This preserves ControlMap's zero-cost guarantee: binding nothing costs nothing, including this dispatch. If your entity overrides onControls() but never sees it fire, check that something in the game calls bindAction/bindAxis.
Parameters
controls(BGE.Controller.ControlMap)
Returns
void
onChangeScene(newScene: BGE.GameScene): void
Inherited from BGE.GameSession#onChangeScene
Overrides: BGE.GameEntity#onChangeScene
Called on every entity added with Game.addEntity(), and on the outgoing scene, whenever a Game.changeScene()/resetScene() takes effect - just before non-persistent entities are destroyed. Override it to save state or clean up.
Parameters
newScene(BGE.GameScene)
Returns
void