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
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.headingConstructor
new SpawnPoints(argName?: string): SpawnPointsParameters
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
BGE.SpawnPoint— the spawn added
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
point(BGE.SpawnPoint)
Returns
BGE.SpawnPoint— point
get(id: string): BGE.SpawnPoint
Parameters
id(string)
Returns
BGE.SpawnPoint— or invalid
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 invaliddefaultId(string, optional, default: "\"\"")
Returns
BGE.SpawnPoint— or invalid if there are no spawns