Engine <TKnownScenes>
Implements
Index
Constructors
Properties
- _originalDisplayMode
- backgroundColor
- browser
- canvas
- canvasElementId
- clock
- currentFrameElapsedMs
- currentFrameLagMs
- debug
- director
- enableCanvasTransparency
- events
- fixedUpdateFps
- fixedUpdateTimestep
- garbageCollectorConfig
- grabWindowFocus
- graphicsContext
- input
- inputMapper
- maxFps
- pageScrollPreventionMode
- pauseAudioWhenHidden
- physics
- pointerScope
- screen
- version
- Context
- InstanceCount
Accessors
Methods
- add
- addScene
- addTimer
- dispose
- emit
- getAntialiasing
- getWorldBounds
- goToScene
- goto
- isDisposed
- isReady
- isRunning
- load
- off
- on
- onFatalException
- onInitialize
- onPostDraw
- onPostUpdate
- onPreDraw
- onPreUpdate
- once
- remove
- removeScene
- removeTimer
- scope
- screenToWorldCoordinates
- screenshot
- setAntialiasing
- showDebug
- start
- stop
- toggleDebug
- toggleInputEnabled
- useCanvas2DFallback
- worldToScreenCoordinates
- useEngine
Constructors
constructor
Creates a new game using the given EngineOptions. By default, if no options are provided, the game will be rendered full screen (taking up all available browser window space). You can customize the game rendering through EngineOptions.
Example:
var game = new ex.Engine({ width: 0, // the width of the canvas height: 0, // the height of the canvas enableCanvasTransparency: true, // the transparencySection of the canvas canvasElementId: '', // the DOM canvas element ID, if you are providing your own displayMode: ex.DisplayMode.FullScreen, // the display mode pointerScope: ex.PointerScope.Document, // the scope of capturing pointer (mouse/touch) events backgroundColor: ex.Color.fromHex('#2185d0') // background color of the engine }); // call game.start, which is a Promise game.start().then(function () { // ready, set, go! });
Type parameters
- TKnownScenes: string = any
Parameters
optionaloptions: EngineOptions<TKnownScenes>
Returns Engine<TKnownScenes>
Properties
publicreadonly_originalDisplayMode
publicbackgroundColor
Sets the background color for the engine.
publicbrowser
Excalibur browser events abstraction used for wiring to native browser events safely
publiccanvas
Direct access to the engine's canvas element
publiccanvasElementId
Direct access to the canvas element ID, if an ID exists
publicclock
Direct access to the excalibur clock
publiccurrentFrameElapsedMs
Returns the current frames elapsed milliseconds
publiccurrentFrameLagMs
Returns the current frame lag when in fixed update mode
publicdebug
Access Excalibur debugging functionality.
Useful when you want to debug different aspects of built in engine features like
- Transform
- Graphics
- Colliders
publicdirector
Scene director, manages all scenes, scene transitions, and loaders in excalibur
publicenableCanvasTransparency
Sets the Transparency for the engine.
publicevents
Listen to and emit events on the Engine
publicoptionalreadonlyfixedUpdateFps
Optionally configure a fixed update fps, this can be desireable if you need the physics simulation to be very stable. When set the update step and physics will use the same elapsed time for each tick even if the graphical framerate drops. In order for the simulation to be correct, excalibur will run multiple updates in a row (at the configured update elapsed) to catch up, for example there could be X updates and 1 draw each clock step.
NOTE: This does come at a potential perf cost because each catch-up update will need to be run if the fixed rate is greater than the current instantaneous framerate, or perf gain if the fixed rate is less than the current framerate.
By default is unset and updates will use the current instantaneous framerate with 1 update and 1 draw each clock step.
WARN: fixedUpdateTimestep
takes precedence over fixedUpdateFps
use whichever is most convenient.
publicoptionalreadonlyfixedUpdateTimestep
Optionally configure a fixed update timestep in milliseconds, this can be desireable if you need the physics simulation to be very stable. When set the update step and physics will use the same elapsed time for each tick even if the graphical framerate drops. In order for the simulation to be correct, excalibur will run multiple updates in a row (at the configured update elapsed) to catch up, for example there could be X updates and 1 draw each clock step.
NOTE: This does come at a potential perf cost because each catch-up update will need to be run if the fixed rate is greater than the current instantaneous framerate, or perf gain if the fixed rate is less than the current framerate.
By default is unset and updates will use the current instantaneous framerate with 1 update and 1 draw each clock step.
WARN: fixedUpdateTimestep
takes precedence over fixedUpdateFps
use whichever is most convenient.
publicreadonlygarbageCollectorConfig
publicreadonlygrabWindowFocus
publicgraphicsContext
Direct access to the ExcaliburGraphicsContext used for drawing things to the screen
publicinput
Access engine input like pointer, keyboard, or gamepad
publicinputMapper
Map multiple input sources to specific game actions actions
publicmaxFps
Optionally set the maximum fps if not set Excalibur will go as fast as the device allows.
You may want to constrain max fps if your game cannot maintain fps consistently, it can look and feel better to have a 30fps game than one that bounces between 30fps and 60fps
publicpageScrollPreventionMode
The mouse wheel scroll prevention mode
publicpauseAudioWhenHidden
Indicates whether audio should be paused when the game is no longer visible.
publicphysics
Direct access to the physics configuration for excalibur
publicreadonlypointerScope
publicscreen
Screen abstraction
publicreadonlyversion
Current Excalibur version string
Useful for plugins or other tools that need to know what features are available
staticContext
staticInstanceCount
Accessors
publiccanvasHeight
The height of the game canvas in pixels, (physical height component of the resolution of the canvas element)
Returns number
publiccanvasWidth
The width of the game canvas in pixels (physical width component of the resolution of the canvas element)
Returns number
publiccurrentScene
publiccurrentSceneName
The current Scene being drawn and updated on screen
Returns string
publicdisplayMode
Indicates the current DisplayMode of the engine.
Returns DisplayMode
publicdrawHeight
Returns the height of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
Returns number
publicdrawWidth
Returns the width of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
Returns number
publichalfCanvasHeight
Returns half height of the game canvas in pixels (half physical height component)
Returns number
publichalfCanvasWidth
Returns half width of the game canvas in pixels (half physical width component)
Returns number
publichalfDrawHeight
Returns half the height of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
Returns number
publichalfDrawWidth
Returns half the width of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
Returns number
publicisDebug
Returns boolean
publicisFullscreen
Indicates whether the engine is set to fullscreen or not
Returns boolean
publicisHiDpi
Returns whether excalibur detects the current screen to be HiDPI
Returns boolean
publicisInitialized
Gets whether the actor is Initialized
Returns boolean
publicloadingComplete
Returns true when loading is totally complete and the player has clicked start
Returns boolean
publicpixelRatio
Returns the calculated pixel ration for use in rendering
Returns number
publicready
Returns boolean
publicrootScene
The default Scene of the game, use Engine.goToScene to transition to different scenes.
Returns Scene<unknown>
publicscenes
Contains all the scenes currently registered with Excalibur
Returns {}
[key string]: Scene | SceneConstructor | SceneWithOptions
publicsnapToPixel
Hints the graphics context to truncate fractional world space coordinates
Returns boolean
Parameters
shouldSnapToPixel: boolean
Returns void
publicstats
Access stats that holds frame statistics.
Returns DebugStats
publictimescale
Gets the current engine timescale factor (default is 1.0 which is 1:1 time)
Returns number
Sets the current engine timescale factor. Useful for creating slow-motion effects or fast-forward effects when using time-based movement.
Parameters
value: number
Returns void
Methods
publicadd
Adds a Scene to the engine, think of scenes in Excalibur as you would levels or menus.
Parameters
sceneKey: string
The key of the scene, must be unique
scene: Scene<unknown> | SceneConstructor | SceneWithOptions
The scene to add to the engine
Returns void
publicaddScene
Adds a Scene to the engine, think of scenes in Excalibur as you would levels or menus.
Type parameters
- TScene: string
Parameters
key: TScene
The name of the scene, must be unique
scene: Scene<unknown> | SceneConstructor | SceneWithOptions
The scene to add to the engine
Returns Engine<TKnownScenes | TScene>
publicaddTimer
publicdispose
Attempts to completely clean up excalibur resources, including removing the canvas from the dom.
To start again you will need to new up an Engine.
Returns void
publicemit
Type parameters
- TEventName: EventKey<EngineEvents>
Parameters
eventName: TEventName
event: EngineEvents[TEventName]
Returns void
publicgetAntialiasing
Return the current smoothing status of the canvas
Returns boolean
publicgetWorldBounds
Returns a BoundingBox of the top left corner of the screen and the bottom right corner of the screen.
Returns BoundingBox
publicgoToScene
Changes the current scene with optionally supplied:
- Activation data
- Transitions
- Loaders
Example:
game.goToScene('myScene', { sceneActivationData: {any: 'thing at all'}, destinationIn: new FadeInOut({duration: 1000, direction: 'in'}), sourceOut: new FadeInOut({duration: 1000, direction: 'out'}), loader: MyLoader });
Scenes are defined in the Engine constructor
const engine = new ex.Engine({ scenes: {...} });
Or by adding dynamically
engine.addScene('myScene', new ex.Scene());
Type parameters
- TData = undefined
Parameters
destinationScene: WithRoot<TKnownScenes>
optionaloptions: GoToOptions<TData>
Returns Promise<void>
publicgoto
Changes the current scene with optionally supplied:
- Activation data
- Transitions
- Loaders
Example:
game.goToScene('myScene', { sceneActivationData: {any: 'thing at all'}, destinationIn: new FadeInOut({duration: 1000, direction: 'in'}), sourceOut: new FadeInOut({duration: 1000, direction: 'out'}), loader: MyLoader });
Scenes are defined in the Engine constructor
const engine = new ex.Engine({ scenes: {...} });
Or by adding dynamically
engine.addScene('myScene', new ex.Scene());
Parameters
destinationScene: WithRoot<TKnownScenes>
optionaloptions: GoToOptions<any>
Returns Promise<void>
publicisDisposed
Returns boolean
publicisReady
Returns Promise<void>
publicisRunning
Returns the Engine's running status, Useful for checking whether engine is running or paused.
Returns boolean
publicload
Another option available to you to load resources into the game. Immediately after calling this the game will pause and the loading screen will appear.
Parameters
loader: DefaultLoader
hideLoader: boolean = false
Returns Promise<void>
publicoff
Type parameters
- TEventName: EventKey<EngineEvents>
Parameters
eventName: TEventName
handler: Handler<EngineEvents[TEventName]>
Returns void
publicon
Event signatures
Type parameters
- TEventName: EventKey<EngineEvents>
Parameters
eventName: TEventName
handler: Handler<EngineEvents[TEventName]>
Returns Subscription
publiconFatalException
The action to take when a fatal exception is thrown
Parameters
e: any
Returns void
publiconInitialize
Overridable implementation
Parameters
engine: Engine<any>
Returns void
publiconPostDraw
Overridable implementation
Parameters
ctx: ExcaliburGraphicsContext
elapsedMs: number
Returns void
publiconPostUpdate
Overridable implementation
Parameters
engine: Engine<any>
elapsedMs: number
Returns void
publiconPreDraw
Overridable implementation
Parameters
ctx: ExcaliburGraphicsContext
elapsedMs: number
Returns void
publiconPreUpdate
Overridable implementation
Parameters
engine: Engine<any>
elapsedMs: number
Returns void
publiconce
Type parameters
- TEventName: EventKey<EngineEvents>
Parameters
eventName: TEventName
handler: Handler<EngineEvents[TEventName]>
Returns Subscription
publicremove
Removes a scene instance from the engine
Parameters
scene: Scene<unknown> | SceneConstructor
The scene to remove
Returns void
publicremoveScene
Removes a Scene instance from the engine
Parameters
scene: Scene<unknown> | SceneConstructor
The scene to remove
Returns void
publicremoveTimer
scope
Anything run under scope can use
useEngine()
to inject the current engineType parameters
- TReturn
Parameters
cb: () => TReturn
Returns TReturn
publicscreenToWorldCoordinates
publicscreenshot
Takes a screen shot of the current viewport and returns it as an HTML Image Element.
Parameters
preserveHiDPIResolution: boolean = false
in the case of HiDPI return the full scaled backing image, by default false
Returns Promise<HTMLImageElement>
publicsetAntialiasing
If supported by the browser, this will set the antialiasing flag on the canvas. Set this to
false
if you want a 'jagged' pixel art look to your image resources.Parameters
isSmooth: boolean
Set smoothing to true or false
Returns void
publicshowDebug
Enable or disable Excalibur debugging functionality.
Parameters
toggle: boolean
a value that debug drawing will be changed to
Returns void
publicstart
Starts the internal game loop for Excalibur after loading any provided assets.
Parameters
optionalloader: DefaultLoader
Returns Promise<void>
publicstop
Stops Excalibur's main loop, useful for pausing the game.
Returns void
publictoggleDebug
Toggle Excalibur debugging functionality.
Returns boolean
publictoggleInputEnabled
Parameters
enabled: boolean
Returns void
publicuseCanvas2DFallback
Switches the engine's graphics context to the 2D Canvas.
Returns void
publicworldToScreenCoordinates
staticuseEngine
Returns Engine<any>
The Excalibur Engine
The Engine is the main driver for a game. It is responsible for starting/stopping the game, maintaining state, transmitting events, loading resources, and managing the scene.