Class: CanvasResizeSystem
CanvasResizeSystem handles automatically resizing the game canvas based on the aspect ratio, maximum resolution, and the HTML wrapper element around the canvas. The system set the canvas to the resolution that meets the following criteria: 1. In the aspect ratio provided. 2. Smaller than or equal to the maximum resolution if provided. 3. Smaller than or equal to the wrapper size in pixels if not full screen. 4. Smaller than or equal to the screen resolution if full screen. 5. The largest possible resolution within these criteria.
Hierarchy
-
↳ CanvasResizeSystem
Table of contents
Constructors
Properties
Methods
Constructors
constructor
+ new CanvasResizeSystem(messageBus
: IMessageBus, canvas
: HTMLCanvasElement, wrapper
: HTMLElement, aspectRatio?
: number, maxResolution?
: null | [number, number], scene?
: IScene, isFullscreen?
: boolean, browserScreen?
: Screen, resizeObserver?
: ResizeObserver, subscriberID?
: number): CanvasResizeSystem
Parameters:
Name | Type | Default value |
---|---|---|
messageBus |
IMessageBus | - |
canvas |
HTMLCanvasElement | - |
wrapper |
HTMLElement | - |
aspectRatio |
number | - |
maxResolution |
null | [number, number] | null |
scene? |
IScene | - |
isFullscreen |
boolean | false |
browserScreen |
Screen | - |
resizeObserver? |
ResizeObserver | - |
subscriberID? |
number | - |
Returns: CanvasResizeSystem
Inherited from: System
Properties
messageBus
• Protected
messageBus: IMessageBus
Reference to the message bus, the fundamental piece of JamJar for communicating with other parts of the engine.
Inherited from: System.messageBus
scene
• Protected
Optional
scene: undefined | IScene
Any scene this system is part of, will change the lifecycle of the system to be part of the scene's lifecycle - it will be destroyed when the scene is destroyed.
subscriberID
• subscriberID: number
Inherited from: System.subscriberID
MESSAGE_SET_ASPECT_RATIO
▪ Readonly
Static
MESSAGE_SET_ASPECT_RATIO: jamjar_set_aspect_ratio= "jamjar_set_aspect_ratio"
Message to set the aspect ratio.
MESSAGE_SET_MAX_RESOLUTION
▪ Readonly
Static
MESSAGE_SET_MAX_RESOLUTION: jamjar_set_max_resolution= "jamjar_set_max_resolution"
Message to set the maximum resolution.
MESSAGE_UPDATE
▪ Readonly
Static
MESSAGE_UPDATE: system_update= "system_update"
Inherited from: System.MESSAGE_UPDATE
Methods
Destroy
▸ Destroy(): void
Destroy destroys the System and unsubscribes it from all messages. The System should be garbage collected after this, unless a direct reference to it exists somewhere. Therefore direct references to systems are discouraged; communication should all be through the message bus.
Returns: void
Inherited from: System
OnDestroy
▸ Protected
OnDestroy(): void
Returns: void
Overrides: System
OnMessage
▸ OnMessage(message
: IMessage): void
Parameters:
Name | Type |
---|---|
message |
IMessage |
Returns: void
Overrides: System
Update
▸ Protected
Update(dt
: number): void
General update method, default empty. Override with custom logic.
Parameters:
Name | Type | Description |
---|---|---|
dt |
number | DeltaTime |
Returns: void
Inherited from: System
onResize
▸ Protected
onResize(): void
Returns: void