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.
Methods
-
getCurrentState()
-
Retrieve the current state of the game
Returns:
{FM.State] The current state of the game. -
getMouseScreenX() → {int}
-
Retrieve the mouse x position on the screen.
Returns:
The x position of the mouse on the screen.- Type
- int
-
getMouseScreenY() → {int}
-
Retrieve the mouse y position on the screen.
Returns:
The y position of the mouse on the screen.- Type
- int
-
getMouseX() → {int}
-
Retrieve the mouse x position in world coordinates.
Returns:
The x position of the mouse cursor.- Type
- int
-
getMouseY() → {int}
-
Retrieve the mouse y position in wolrd coordinates.
Returns:
The y position of the mouse cursor.- Type
- int
-
getName() → {string}
-
Retrieve the name of the game.
Returns:
The name of the game.- Type
- string
-
getScreenHeight()
-
Retrieve the chosen height of the game screen.
Returns:
{int] The height of the screen. -
getScreenWidth() → {int}
-
Retrieve the chosen width of the game screen.
Returns:
The width of the screen.- Type
- int
-
isDebugActivated() → {boolean}
-
Check if the debug button was pressed and if debug info should be displayed.
Returns:
Whether the debug mode is activated or not.- Type
- boolean
-
isKeyPressed(key) → {boolean}
-
Check if a key is pressed.
Parameters:
Name Type Description keyint The key to test if it is pressed. 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 keyint The key to test if it has been released or not. Returns:
Whether the given key was just released or not.- Type
- boolean
-
isMouseClicked() → {boolean}
-
Check if the mouse has been clicked.
Returns:
Whether the mouse left button has been clicked or not.- Type
- boolean
-
isMousePressed() → {boolean}
-
Check if a mouse button is pressed.
Returns:
Whether the mouse left button is pressed.- Type
- boolean
-
isMouseReleased() → {boolean}
-
Check if a mouse button has been released.
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 pCanvasIdstring The string ID of the canvas on which to run the game. pNamestring The name of the game. pWidthint The width of the screen. pHeightint The height of the screen. pFirstStateFM.State The first state to perform. pCustomPreloaderFM.Preloader Preloader to be used if you want a custom preloader. -
setBackgroundColor(newColor)
-
Change the game's background color.
Parameters:
Name Type Description newColorstring The color to set the background to. -
switchState(newState)
-
Switch between two states.
Parameters:
Name Type Description newStateFM.State The new state to switch to.