Room
Extends: GameEntity
A Room is just a GameEntity that represents a distinct scene/level - see Game.defineRoom()/changeRoom(). Only one Room can be "current" at a time; the current Room is processed like any other entity (its onUpdate/onInput/etc. hooks fire every frame) but is never itself placed in Game.sortedEntities, so Game.handleRoomChange()'s automatic non-persistent-entity cleanup never applies to a Room's own drawables.
To compensate, Room provides a default onChangeRoom(): any drawable this room added directly to itself (via addDrawable()/addImage()/etc.) is removed whenever the game changes to a different room. This mirrors what already happens automatically to every other non-persistent GameEntity. Nothing happens when "changing" to this same room (e.g. Game.resetRoom()), since onCreate() runs again immediately after and typically re-adds everything anyway.
A room that wants some or all of its own drawables to survive a transition can opt out two ways:
- set
persistDrawablesAcrossRoomChange = trueto keep every directly-added drawable, or - override
onChangeRoom()with custom cleanup logic; overriding replaces this default entirely unless the override callssuper.onChangeRoom(newRoom).
Properties
persistDrawablesAcrossRoomChange(boolean) — Whether this room's own directly-added drawables should survive a change to a ' different room, instead of being removed by this class's defaultonChangeRoom().
Constructor
new Room(gameEngine: Game, args?: roAssociativeArray): RoomParameters
gameEngine(Game)args(roAssociativeArray, optional, default: "{}")
Instance Methods
onChangeRoom(newRoom: Room): void
Default room-change hook: removes every drawable this room added directly to itself (see GameEntity.addDrawable()) when switching away to a different room, unless persistDrawablesAcrossRoomChange is true. A subclass that overrides onChangeRoom() only gets this behavior if its override calls super.onChangeRoom(newRoom).
Parameters
newRoom(Room) — The room being changed to
Returns
void