GameCanvas
The GameCanvas
class is a singleton class that manages the game canvas.
info
Prefer to get the unique instance of this service from the ServiceContainer
like:
const gameCanvas = ServiceContainer.GameCanvas;
Getters
instance
- Type:
GameCanvas
Returns the instance of the GameCanvas (Usage of Service Container is recommanded).
canvas
- Type:
HTMLCanvasElement
The canvas element.
context
- Type:
CanvasRenderingContext2D
The canvas context.
baseSize
-Type: Point
The base size of canvas. This is useful for calculating positions and dimensions.
scale
- Type:
number
The scale of the canvas.
position
- Type:
Point
The position of the canvas.
Methods
init
Prototype
init(options?: CanvasOptions): GameCanvas
Initialize the canvas.
Parameters
options
(optional)- Type:
CanvasOptions
- The options to set the canvas
- Type:
Return
void
Example
ServiceContainer.GameCanvas.init();
or with custom configuration:
ServiceContainer.GameCanvas.init({
size: new Point(800, 600),
parent: document.body,
imageSmoothingEnabled: true,
backgroundColor: '#000'
});
fullscreen
Prototype
fullscreen(): GameCanvas
Sets the canvas to fullscreen.
Return
- Type:
GameCanvas
The instance of the GameCanvas class.
Example
ServiceContainer.GameCanvas.fullscreen();
exitFullscreen
Prototype
exitFullscreen(): GameCanvas
Exits fullscreen mode.
Return
- Type:
GameCanvas
The instance of the GameCanvas class.
Example
ServiceContainer.GameCanvas.exitFullscreen();
toggleFullscreen
Prototype
toggleFullscreen(): GameCanvas
Toggles fullscreen mode.
Return
- Type:
GameCanvas
The instance of the GameCanvas class.
Example
ServiceContainer.GameCanvas.toggleFullscreen();
clearScreen
Prototype
clearScreen(): GameCanvas
Clears the canvas.
Return
- Type:
GameCanvas
The instance of the GameCanvas class.
Example
ServiceContainer.GameCanvas.clearScreen();