[SOLVED] SpriteAnimationClip() confusion

Project Link: https://playcanvas.com/editor/scene/1142476
Script Link: https://playcanvas.com/editor/code/790861?tabs=46937720,46941104

> Hello! I am trying to create a sprite animation/clip handler, and even though I read through the docs, I still need clearance on how the SpriteAnimationClip() function works!

var AnimationHandler = pc.createScript('animationHandler');

// initialize code called once per entity
AnimationHandler.prototype.initialize = function() {
    
};

// update code called every frame
AnimationHandler.prototype.update = function(dt) {
    
    if (this.app.keyboard.isPressed(pc.KEY_LEFT)) {
    SpriteAnimationClip.play('moving');
    } 
};

Above is a completely incomplete script, but is just a reference. Also, is there a way I can detect if a sprite is not moving? Is there an event listener for that?

Hi @CRAYPHiSHQUESTIONS,

Try this instead:

var AnimationHandler = pc.createScript('animationHandler');

// initialize code called once per entity
AnimationHandler.prototype.initialize = function() {
    
};

// update code called every frame
AnimationHandler.prototype.update = function(dt) {
    
    if (this.app.keyboard.isPressed(pc.KEY_LEFT)) {
    this.entity.sprite.play('moving');
    } 
};
1 Like

Wow, thank you so much! Somehow I didn’t come across this!

1 Like