Create a new SpriteComponent instance.
The ComponentSystem that created this Component.
The Entity that this Component is attached to.
The Entity that this Component is attached to.
The ComponentSystem used to create this Component.
The name of the clip to play automatically when the component is enabled and the clip exists.
Assign sprite to a specific batch group (see BatchGroup). Default is -1 (no group).
A dictionary that contains SpriteAnimationClips.
The current clip being played.
The draw order of the component. A higher value means that the component will be rendered on top of other components in the same layer. This is not used unless the layer's sort order is set to SORTMODE_MANUAL.
Enables or disables the component.
Flip the X axis when rendering a sprite.
Flip the Y axis when rendering a sprite.
The frame counter of the sprite. Specifies which frame from the current sprite asset to render.
The height of the sprite when rendering using 9-Slicing. The width and height are only used when the render mode of the sprite asset is Sliced or Tiled.
An array of layer IDs (Layer#id) to which this sprite should belong.
The opacity of the sprite.
A global speed modifier used when playing sprite animation clips.
The current sprite.
The asset id or the Asset of the sprite to render. Only works for SPRITETYPE_SIMPLE sprites.
The type of the SpriteComponent. Can be:
Defaults to SPRITETYPE_SIMPLE.
The width of the sprite when rendering using 9-Slicing. The width and height are only used when the render mode of the sprite asset is Sliced or Tiled.
Creates and adds a new SpriteAnimationClip to the component's clips.
Data for the new animation clip.
The new clip that was added.
Get an animation clip by name.
The name of the clip.
The clip.
Fire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
obj.fire('test', 'This is the message');
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
obj.on('test', function () { }); // bind an event to 'test'
obj.hasEvent('test'); // returns true
obj.hasEvent('hello'); // returns false
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
obj.on('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
const evt = obj.on('test', function (a, b) {
console.log(a + b);
});
// some time later
evt.off();
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
obj.once('test', function (a, b) {
console.log(a + b);
});
obj.fire('test', 1, 2); // prints 3 to the console
obj.fire('test', 1, 2); // not going to get handled
Plays a sprite animation clip by name. If the animation clip is already playing then this will do nothing.
The name of the clip to play.
The clip that started playing.
Static
EVENT_Fired when an animation clip stops playing because it reached its end. The handler is passed the SpriteAnimationClip that ended.
entity.sprite.on('end', (clip) => {
console.log(`Animation clip ${clip.name} ended.`);
});
Static
EVENT_Fired when an animation clip reached the end of its current loop. The handler is passed the SpriteAnimationClip that looped.
entity.sprite.on('loop', (clip) => {
console.log(`Animation clip ${clip.name} looped.`);
});
Static
EVENT_Fired when an animation clip is paused. The handler is passed the SpriteAnimationClip that was paused.
entity.sprite.on('pause', (clip) => {
console.log(`Animation clip ${clip.name} paused.`);
});
Static
EVENT_Fired when an animation clip starts playing. The handler is passed the SpriteAnimationClip that started playing.
entity.sprite.on('play', (clip) => {
console.log(`Animation clip ${clip.name} started playing.`);
});
Static
EVENT_Fired when an animation clip is resumed. The handler is passed the SpriteAnimationClip that was resumed.
entity.sprite.on('resume', (clip) => {
console.log(`Animation clip ${clip.name} resumed.`);
});
Static
EVENT_Fired when an animation clip is stopped. The handler is passed the SpriteAnimationClip that was stopped.
entity.sprite.on('stop', (clip) => {
console.log(`Animation clip ${clip.name} stopped.`);
});
Enables an Entity to render a simple static sprite or sprite animations.