Path to the image resource or a base64 string representing an image "data:image/png;base64,iVB..."
Optionally load texture with cache busting
Optionally load texture with cache busting
Direct access to the game object event dispatcher.
The height of the texture in pixels
Populated once loading is complete
A Promise that resolves when the Texture is loaded.
Path to the image resource or a base64 string representing an image "data:image/png;base64,iVB..."
The type to expect as a response: "" | "arraybuffer" | "blob" | "document" | "json" | "text";
The width of the texture in pixels
Emits a new event
Name of the event to emit
Data associated with this event
Returns the loaded data once the resource is loaded
Returns true if the Texture is completely loaded and is ready to be drawn.
Begins loading the texture and returns a promise to be resolved on completion
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.
Name of the event to listen for
Event handler for the thrown event
Alias for addEventListener
. You can listen for a variety of
events off of the engine; see the events section below for a complete list.
Name of the event to listen for
Event handler for the thrown event
Once listens to an event one time, then unsubscribes from that event
The name of the event to subscribe to once
The handler of the event that will be auto unsubscribed
This method is meant to be overridden to handle any additional processing. Such as decoding downloaded audio bits.
Sets the data for this resource directly
The Texture object allows games built in Excalibur to load image resources. Texture is an Loadable which means it can be passed to a Loader to pre-load before starting a level or game.
Textures are the raw image so to add a drawing to a game, you must create a Sprite. You can use Texture.asSprite to quickly generate a Sprite instance.
Pre-loading textures
Pass the Texture to a Loader to pre-load the asset. Once a Texture is loaded, you can generate a Sprite with it.
var txPlayer = new ex.Texture('/assets/tx/player.png'); var loader = new ex.Loader([txPlayer]); game.start(loader).then(function() { var player = new ex.Actor(); player.addDrawing(txPlayer); game.add(player); });