SpawnPoints

The places a scene can start the player, by id, and which one this visit's args ask for. A scene makes one in onCreate() (scenes are reused, so make a new one or clear() it each visit), adds its spawns, then resolves the args it was changed to with. An exit into the scene names a spawn in its args, e.g. {spawn: "gate"} - see BGE.SceneExits.

Properties

  • argName (string) — The args field resolve() reads the spawn id from

Example

CODE
m.spawns = new BGE.SpawnPoints()
m.spawns.add("gate", BGE.Math.VectorOps.create(0, 0, 400), BGE.Math.PI)
m.spawns.add("start", BGE.Math.VectorOps.create(0, 0, 0))
spawn = m.spawns.resolve(args, "start")
m.player.position.x = spawn.position.x
m.player.position.z = spawn.position.z
m.player.rotation.y = spawn.heading

Constructor

new SpawnPoints(argName?: string): SpawnPoints

Parameters

  • argName (string, optional, default: "\"spawn\"") — the args field resolve() reads the spawn id from

Instance Methods

add( id: string, position: BGE.Math.Vector, heading?: float, ): BGE.SpawnPoint

Adds a spawn. One with the same id is replaced, keeping its place in the order.

Parameters

  • id (string)
  • position (BGE.Math.Vector)
  • heading (float, optional, default: "0.0") — radians

Returns

addPoint(point: BGE.SpawnPoint): BGE.SpawnPoint

Adds a spawn you made, e.g. a subclass of BGE.SpawnPoint. One with the same id is replaced, keeping its place in the order.

Parameters

Returns

get(id: string): BGE.SpawnPoint

Parameters

  • id (string)

Returns

has(id: string): boolean

Parameters

  • id (string)

Returns

  • boolean

remove(id: string): void

Parameters

  • id (string)

Returns

  • void

clear(): void

Returns

  • void

count(): integer

Returns

  • integer

getIds(): Array.<string>

Every spawn's id, in the order added.

Returns

  • Array.<string>

resolve( args: roAssociativeArray, defaultId?: string, ): BGE.SpawnPoint

Where to start this visit: the spawn args[argName] names, else defaultId, else the first one added. Override it to choose some other way.

Parameters

  • args (roAssociativeArray) — the scene's args, e.g. from onCreate(); may be invalid
  • defaultId (string, optional, default: "\"\"")

Returns