Loader
Hierarchy
- DefaultLoader
- Loader
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
Parameters
optionaloptions: LoaderOptions
Optionally provide options to loader
Returns Loader
Properties
publicbackgroundColor
Gets or sets the background color of the loader as a hex string
publiccanvas
data
Data associated with a loadable
publicengine
publicevents
publicloadingBarColor
Gets or sets the color of the loading bar, default is [[Color.White]]
publicloadingBarPosition
Positions the top left corner of the loading bar If not set, the loader automatically positions the loading bar
publiclogo
publiclogoHeight
publiclogoPosition
Positions the top left corner of the logo image If not set, the loader automatically positions the logo
publiclogoWidth
publicplayButtonPosition
Positions the top left corner of the play button. If not set, the loader automatically positions the play button
publicplayButtonText
Get/set play button text
publicscreen
publicsuppressPlayButton
Accessors
publicplayButtonElement
Returns HTMLButtonElement
publicplayButtonRootElement
Returns HTMLElement
publicprogress
Returns the progress of the loader as a number between [0, 1] inclusive.
Returns number
publicresources
Returns readonly Loadable<any>[]
Methods
publicaddResource
Add a resource to the loader to load
Parameters
loadable: Loadable<any>
Resource to add
Returns void
publicaddResources
Add a list of resources to the loader to load
Parameters
loadables: Loadable<any>[]
The list of resources to load
Returns void
publicareResourcesLoaded
Returns Promise<void>
publicdispose
Clean up generated elements for the loader
Returns void
publicemit
Type parameters
- TEventName: EventKey<LoaderEvents>
Parameters
eventName: TEventName
event: LoaderEvents[TEventName]
Returns void
publichidePlayButton
Returns void
publicisLoaded
Returns true if the loader has completely loaded all resources
Returns boolean
publicload
Not meant to be overridden
Begin loading all of the supplied resources, returning a promise that resolves when loading of all is complete AND the user has interacted with the loading screen
Returns Promise<Loadable<any>[]>
publicmarkResourceComplete
Returns void
publicoff
Type parameters
- TEventName: EventKey<LoaderEvents>
Parameters
eventName: TEventName
handler: Handler<LoaderEvents[TEventName]>
Returns void
publicon
Type parameters
- TEventName: EventKey<LoaderEvents>
Parameters
eventName: TEventName
handler: Handler<LoaderEvents[TEventName]>
Returns Subscription
publiconAfterLoad
Overridable lifecycle method, called after loading has completed
Returns Promise<void>
publiconBeforeLoad
Overridable lifecycle method, called directly before loading starts
Returns Promise<void>
publiconDraw
Loader draw function. Draws the default Excalibur loading screen. Override
logo
,logoWidth
,logoHeight
andbackgroundColor
properties to customize the drawing, or just override entire method.Parameters
ctx: CanvasRenderingContext2D
Returns void
publiconInitialize
Called by the engine before loading
Parameters
engine: Engine<any>
Returns void
onUpdate
Optionally override the onUpdate
Parameters
engine: Engine<any>
elapsedMilliseconds: number
Returns void
publiconUserAction
Return a promise that resolves when the user interacts with the loading screen in some way, usually a click.
It's important to implement this in order to unlock the audio context in the browser. Browsers automatically prevent audio from playing until the user performs an action.
Returns Promise<void>
publiconce
Type parameters
- TEventName: EventKey<LoaderEvents>
Parameters
eventName: TEventName
handler: Handler<LoaderEvents[TEventName]>
Returns Subscription
publicshowPlayButton
Shows the play button and returns a promise that resolves when clicked
Returns Promise<void>
publicstartButtonFactory
Return a html button element for excalibur to use as a play button
Returns HTMLButtonElement
Pre-loading assets
The loader provides a mechanism to preload multiple resources at one time. The loader must be passed to the engine in order to trigger the loading progress bar.
The [[Loader]] itself implements [[Loadable]] so you can load loaders.
Example: Pre-loading resources for a game
Customize the Loader
The loader can be customized to show different, text, logo, background color, and button.