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 |
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 |
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 |
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 |
getGroup(groupName) → {Group}
Get a group from the collection.
Parameters:
Name | Type | Description |
---|---|---|
groupName |
string | the name of the group |
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 |
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.
Typically used in loops that involve all sprites in this group.
Parameters:
Name | Type | Description |
---|---|---|
groupName |
string | the name of the group |
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.
Must be implemented by extending class.
removeAllSpritesFromGroup(groupName)
Remove all sprites from a group in the collection.
Parameters:
Name | Type | Description |
---|---|---|
groupName |
string | the name of the group |
removeSpriteFromGroup(sprite, groupName)
Remove a sprite from a group in the collection.
(Note: simpler to use the Sprite class destroy method.)
(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 |
resume()
Resume function is called by Game setScreen function,
which enables screen data to be updated, if needed.
Optional to implement in extending class.
Optional to implement in extending class.
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.
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.
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.
Must be implemented by extending class.
updateGroups(deltaTime)
Update all sprites in all groups in the collection.
Can be enabled/disabled with setPaused.
Can be enabled/disabled with setPaused.
Parameters:
Name | Type | Description |
---|---|---|
deltaTime |
the change in time since the last clock update |