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.Input.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!
});
Sets the background color for the engine.
Excalibur browser events abstraction used for wiring to native browser events safely
Direct access to the engine's canvas element
Direct access to the canvas element ID, if an ID exists
Direct access to the excalibur clock
The current Scene being drawn and updated on screen
Access Excalibur debugging functionality.
Useful when you want to debug different aspects of built in engine features like
Sets the Transparency for the engine.
Direct access to the game object event dispatcher.
Direct access to the ExcaliburGraphicsContext used for drawing things to the screen
Access engine input like pointer, keyboard, or gamepad
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
The mouse wheel scroll prevention mode
Indicates whether audio should be paused when the game is no longer visible.
The default Scene of the game, use Engine.goToScene to transition to different scenes.
Contains all the scenes currently registered with Excalibur
Screen abstraction
The height of the game canvas in pixels, (physical height component of the resolution of the canvas element)
The width of the game canvas in pixels (physical width component of the resolution of the canvas element)
Indicates the current DisplayMode of the engine.
Returns the height of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
Returns the width of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
Returns half height of the game canvas in pixels (half physical height component)
Returns half width of the game canvas in pixels (half physical width component)
Returns half the height of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
Returns half the width of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
Indicates whether the engine is set to fullscreen or not
Returns whether excalibur detects the current screen to be HiDPI
Gets whether the actor is Initialized
Returns true when loading is totally complete and the player has clicked start
Returns the calculated pixel ration for use in rendering
Hints the graphics context to truncate fractional world space coordinates
Hints the graphics context to truncate fractional world space coordinates
Access stats that holds frame statistics.
Gets the current engine timescale factor (default is 1.0 which is 1:1 time)
Sets the current engine timescale factor. Useful for creating slow-motion effects or fast-forward effects when using time-based movement.
Adds a Scene to the engine, think of scenes in Excalibur as you would levels or menus.
The key of the scene, must be unique
The scene to add to the engine
Adds a Timer to the currentScene.
The timer to add to the currentScene.
Adds a TileMap to the currentScene, once this is done the TileMap will be drawn and updated.
Adds an actor to the currentScene of the game. This is synonymous
to calling engine.currentScene.add(actor)
.
Actors can only be drawn if they are a member of a scene, and only the currentScene may be drawn or updated.
The actor to add to the currentScene
Adds a ScreenElement to the currentScene of the game, ScreenElements do not participate in collisions, instead the remain in the same place on the screen.
The ScreenElement to add to the currentScene
Adds a Timer to the currentScene.
The timer to add to the currentScene.
Emits a new event
Name of the event to emit
Data associated with this event
Return the current smoothing status of the canvas
Returns a BoundingBox of the top left corner of the screen and the bottom right corner of the screen.
Changes the currently updating and drawing scene to a different, named scene. Calls the Scene lifecycle events.
The key of the scene to transition to.
Returns the Engine's running status, Useful for checking whether engine is running or paused.
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.
Alias for removeEventListener
. If only the eventName is specified
it will remove all handlers registered for that specific event. If the eventName
and the handler instance are specified only that handler will be removed.
Event signatures
Event signatures
The action to take when a fatal exception is thrown
Overridable implementation
Overridable implementation
Overridable implementation
Overridable implementation
Overridable implementation
Once listens to an event one time, then unsubscribes from that event
Removes a scene instance from the engine
The scene to remove
Removes a scene from the engine by key
The scene to remove
Removes a Timer from the currentScene.
The timer to remove to the currentScene.
Removes a TileMap from the currentScene, it will no longer be drawn or updated.
Removes an actor from the currentScene of the game. This is synonymous
to calling engine.currentScene.removeChild(actor)
.
Actors that are removed from a scene will no longer be drawn or updated.
The actor to remove from the currentScene.
Removes a ScreenElement to the scene, it will no longer be drawn or updated
The ScreenElement to remove from the currentScene
Removes a Timer from the currentScene.
The timer to remove to the currentScene.
Takes a screen shot of the current viewport and returns it as an HTML Image Element.
in the case of HiDPI return the full scaled backing image, by default false
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.
Set smoothing to true or false
Enable or disable Excalibur debugging functionality.
a value that debug drawing will be changed to
Starts the internal game loop for Excalibur after loading any provided assets.
Stops Excalibur's main loop, useful for pausing the game.
Toggle Excalibur debugging functionality.
Switches the engine's graphics context to the 2D Canvas.
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.