Display
Description: Manages the game canvas, handles rendering, input events, and the game loop.
Constructor
new Display()
- Initializes a new display object with a canvas, context, and camera.
Methods
start(width = 480, height = 270, no = document.body)
Description: Starts the game loop and sets up the canvas.
Parameters:
width
(number, optional): Canvas width (default: 480).height
(number, optional): Canvas height (default: 270).no
(HTMLElement, optional): Parent element to append the canvas to (default:document.body
).
Returns: None.
addEventListeners()
Description: Adds event listeners for keyboard, mouse, and touch input.
Parameters: None.
Returns: None.
clear()
Description: Clears the canvas.
Parameters: None.
Returns: None.
borderStyle(borderStyle)
Description: Sets the canvas border style (e.g., "solid", "dashed").
Parameters: borderStyle
(string).
Returns: None.
stop()
Description: Stops the game loop.
Parameters: None.
Returns: None.
borderSize(borderSize)
Description: Sets the canvas border size (e.g., "1px").
Parameters: borderSize
(string).
Returns: None.
backgroundColor(color)
Description: Sets the canvas background color (e.g., "black").
Parameters: color
(string).
Returns: None.
borderColor(color)
Description: Sets the canvas border color (e.g., "red").
Parameters: color
(string).
Returns: None.
fontColor(color)
Description: Sets the canvas font color (e.g., "white").
Parameters: color
(string).
Returns: None.
scale(width, height)
Description: Resizes the canvas.
Parameters:
width
(number): New canvas width.height
(number): New canvas height.
Returns: None.
add(x)
Description: Adds a component to the rendering list.
Parameters: x
(Component): The component to add.
Returns: None.
updat()
Description: Updates and renders all components, applying camera translation.
Parameters: None.
Returns: None.