Class: Screen

Screen(game)

A Screen contains the code for each individual game screen, such as a title screen, menu screens, and screens corresponding to each room or level in the game.
Each screen manages a collection of Groups, each of which stores a list of Sprites, that are rendered by the Game class, in the order in which they were added.
Classes which extend Screen must implement the initialize and update methods.

Constructor

new Screen(game)

Creates a collection to store Groups, a default Group named "main", a variable to reference the Game containing this screen, and calls the initialize method.
Parameters:
Name Type Description
game Game a reference to the Game containing this Screen
Source:

Methods

addSpriteToGroup(sprite, groupName)

Add a sprite to a group in the collection.
Parameters:
Name Type Default Description
sprite Sprite the sprite to be added
groupName string main the name of the group
Source:

createGroup(groupName)

Create a new group and add it to the collection.
Parameters:
Name Type Description
groupName string the name that will be used to reference the group
Source:

drawGroups(context)

Draw all sprites in all groups in the collection (in the order they were added).
Parameters:
Name Type Description
context the graphics context object associated to the game canvas
Source:

getGroup(groupName) → {Group}

Get a group from the collection.
Parameters:
Name Type Description
groupName string the name of the group
Source:
Returns:
the group stored with the given name
Type
Group

getGroupSpriteCount(groupName) → {number}

Get the number of sprites stored in the group with the given name.
Parameters:
Name Type Description
groupName string the name of the group
Source:
Returns:
the number of sprites in the group
Type
number

getGroupSpriteList(groupName) → {List}

Get the list of sprites stored in the group with the given name.
Typically used in loops that involve all sprites in this group.
Parameters:
Name Type Description
groupName string the name of the group
Source:
Returns:
the list of sprites in the group
Type
List

initialize()

Create all objects and any other initialization code required by this screen.
Must be implemented by extending class.
Source:

removeAllSpritesFromGroup(groupName)

Remove all sprites from a group in the collection.
Parameters:
Name Type Description
groupName string the name of the group
Source:

removeSpriteFromGroup(sprite, groupName)

Remove a sprite from a group in the collection.
(Note: simpler to use the Sprite class destroy method.)
Parameters:
Name Type Description
sprite Sprite the sprite to be removed
groupName string the name of the group
Source:

resume()

Resume function is called by Game setScreen function, which enables screen data to be updated, if needed.
Optional to implement in extending class.
Source:

setPaused()

Pauses the game: enables/disables automatic Group updates, which in turn calls the Sprite update functions.
The Screen update function is still called, so Input functions can still be checked, to enable the user to un-pause the currently running game.
Source:

update()

Update all game logic for this screen, such as processing player input, interaction between sprites, and game event conditions (such as win/lose).
Must be implemented by extending class.
Source:

updateGroups(deltaTime)

Update all sprites in all groups in the collection.
Can be enabled/disabled with setPaused.
Parameters:
Name Type Description
deltaTime the change in time since the last clock update
Source: