SceneExits

A scene's ways out: areas that change to another scene when the player walks in. Each visit leaves once - after the first exit is taken the rest are ignored, so a player standing in a doorway during the fade doesn't ask again. If the change is refused (another transition is running) nothing is used up and the next update() tries again.

A scene makes one in onCreate() (scenes are reused, so make a new one or clear() it each visit), adds its exits, and calls update() with the player's position each frame - from onPostUpdate() to see where everyone ended up this frame. Shapes: BGE.RectExitArea, BGE.CircleExitArea, BGE.GridCellsExitArea, or subclass BGE.ExitArea. Subclass BGE.SceneExit for another trigger condition, and this class to change scene some other way (changeSceneFor()) or react to leaving (onLeave()). trigger() takes an exit directly, e.g. from a collider's onCollisionEnter().

Properties

  • enabled (boolean) — While false, update() takes no exits
  • game (BGE.Game)
  • exits (Array.<BGE.SceneExit>) — In the order added: the first that triggers wins

Example

CODE
m.exits = new BGE.SceneExits(m.game)
m.exits.add(new BGE.RectExitArea(-100, 380, 200, 40), "TownScene", {spawn: "gate"})
m.exits.add(new BGE.CircleExitArea(m.doorPosition, 60), "ChapelScene")
' in onPostUpdate():
m.exits.update(m.player.position)

Constructor

new SceneExits(game: BGE.Game): SceneExits

Parameters


Instance Methods

add( area: BGE.ExitArea, sceneName: string, args?: roAssociativeArray, ): BGE.SceneExit

Adds an exit to a scene.

Parameters

  • area (BGE.ExitArea)
  • sceneName (string)
  • args (roAssociativeArray, optional, default: "{}") — passed to the next scene

Returns

  • BGE.SceneExit — the exit, e.g. to set fadeSeconds or enabled

addExit(sceneExit: BGE.SceneExit): BGE.SceneExit

Adds an exit you made, e.g. a subclass of BGE.SceneExit.

Parameters

Returns

getAll(): Array.<BGE.SceneExit>

Every exit, in the order added.

Returns

count(): integer

Returns

  • integer

clear(): void

Drops every exit and forgets having left, for the scene's next visit.

Returns

  • void

hasLeft(): boolean

Whether an exit has changed scene this visit.

Returns

  • boolean

update(position: BGE.Math.Vector): boolean

Takes the first exit (in the order added) whose isTriggeredBy() passes for a position. Does nothing while disabled or once one has been taken.

Parameters

  • position (BGE.Math.Vector) — e.g. the player's

Returns

  • boolean — whether this changed scene

trigger(sceneExit: BGE.SceneExit): boolean

Leaves through an exit wherever the player is, unless one has been taken already. An exit whose change is refused with no transition running (e.g. an undefined scene) is disabled.

Parameters

Returns

  • boolean — whether this changed scene

changeSceneFor(sceneExit: BGE.SceneExit): boolean

protected

Parameters

Returns

  • boolean

onLeave(sceneExit: BGE.SceneExit): void

protected

Parameters

Returns

  • void