Constructor
new Game(width, height, divID)
Set up the canvas where the game will appear.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
width |
number | 800 | the width of the canvas containing the game |
height |
number | 600 | the height of the canvas containing the game |
divID |
string | null | the ID of the HTML div element where the canvas should be placed; if not included, a div element will be created |
Methods
addScreen(screenName, screenObject)
Add a Screen object to this game.
Parameters:
Name | Type | Description |
---|---|---|
screenName |
string | the name that should be used to refer to the screen when using the setScreen method |
screenObject |
Screen | the screen to be added to the game |
clearCanvas(clearColor)
Clear the game canvas by drawing a colored rectangle that fills the canvas.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
clearColor |
string | #000000 | name or hex code of color to use when clearing the canvas |
getData()
Retrieve data previously stored by setData.
initialize()
Add Screen objects and set first screen to display.
Must be implemented by extending class.
Must be implemented by extending class.
quit()
Quit the game: stop the game loop, stop the game from listening for user keyboard input, and clear the canvas.
setData(dataName, dataValue)
Store data at a global level so it is accessible to all screens via getData.
Note: required data must be set before screens are created.
Note: required data must be set before screens are created.
Parameters:
Name | Type | Description |
---|---|---|
dataName |
string | name used to reference and retrieve data later |
dataValue |
object | value to be stored |
setScreen(screenName)
Set the active Screen object for this game.
During each frame, the game calls the Screen.update method and renders the Sprites in the Group of the active screen.
During each frame, the game calls the Screen.update method and renders the Sprites in the Group of the active screen.
Parameters:
Name | Type | Description |
---|---|---|
screenName |
string | the name of the associated screen initially specified by the addScreen method |
setScreenFadeTransition(screenFadeTransition, screenFadeDuration, screenFadeColor)
Determine whether current screen will fade out and
next screen will fade in, when the screen is changed
using setScreen,
and set the screen fade duration and color.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
screenFadeTransition |
boolean | true | whether or not screens will fade in and fade out |
screenFadeDuration |
number | 1 | the amount of time to fade in and fade out |
screenFadeColor |
string | #000000 | the color of the fade between screens |
start()
Start the game: create game objects and run the initialize method.