Class: Game

Game

new Game()

The Game object is a singleton that represents the game application and contains all the necessary information and methods to handle its execution.
Author:
  • Simon Chauvin
Source:

Methods

getCurrentState()

Retrieve the current state of the game
Source:
Returns:
{FM.State] The current state of the game.

getMouseScreenX() → {int}

Retrieve the mouse x position on the screen.
Source:
Returns:
The x position of the mouse on the screen.
Type
int

getMouseScreenY() → {int}

Retrieve the mouse y position on the screen.
Source:
Returns:
The y position of the mouse on the screen.
Type
int

getMouseX() → {int}

Retrieve the mouse x position in world coordinates.
Source:
Returns:
The x position of the mouse cursor.
Type
int

getMouseY() → {int}

Retrieve the mouse y position in wolrd coordinates.
Source:
Returns:
The y position of the mouse cursor.
Type
int

getName() → {string}

Retrieve the name of the game.
Source:
Returns:
The name of the game.
Type
string

getScreenHeight()

Retrieve the chosen height of the game screen.
Source:
Returns:
{int] The height of the screen.

getScreenWidth() → {int}

Retrieve the chosen width of the game screen.
Source:
Returns:
The width of the screen.
Type
int

isDebugActivated() → {boolean}

Check if the debug button was pressed and if debug info should be displayed.
Source:
Returns:
Whether the debug mode is activated or not.
Type
boolean

isKeyPressed(key) → {boolean}

Check if a key is pressed.
Parameters:
Name Type Description
key int The key to test if it is pressed.
Source:
Returns:
Whether the given key is pressed or not.
Type
boolean

isKeyReleased(key) → {boolean}

Check if a key has been released.
Parameters:
Name Type Description
key int The key to test if it has been released or not.
Source:
Returns:
Whether the given key was just released or not.
Type
boolean

isMouseClicked() → {boolean}

Check if the mouse has been clicked.
Source:
Returns:
Whether the mouse left button has been clicked or not.
Type
boolean

isMousePressed() → {boolean}

Check if a mouse button is pressed.
Source:
Returns:
Whether the mouse left button is pressed.
Type
boolean

isMouseReleased() → {boolean}

Check if a mouse button has been released.
Source:
Returns:
Whether the mouse left button was released or not.
Type
boolean

run(pCanvasId, pName, pWidth, pHeight, pFirstState, pCustomPreloader)

Start running the game.
Parameters:
Name Type Description
pCanvasId string The string ID of the canvas on which to run the game.
pName string The name of the game.
pWidth int The width of the screen.
pHeight int The height of the screen.
pFirstState FM.State The first state to perform.
pCustomPreloader FM.Preloader Preloader to be used if you want a custom preloader.
Source:

setBackgroundColor(newColor)

Change the game's background color.
Parameters:
Name Type Description
newColor string The color to set the background to.
Source:

switchState(newState)

Switch between two states.
Parameters:
Name Type Description
newState FM.State The new state to switch to.
Source: