Sprite clip stops when releasing mouse click


need help on this, can’t figure out how can I make my char do full attack anim on mouse click.
it cancels anim on releasing mouse click, need to hold click for it do full anim. please and thank you
below is my script:

var Player = pc.createScript('player');

// initialize code called once per entity
Player.prototype.initialize = function() {

};

// update code called every frame
Player.prototype.update = function(dt) {
    if(this.app.keyboard.isPressed(pc.KEY_D)){
        this.entity.translateLocal(0.04, 0, 0)
        this.entity.sprite.flipX = false;
        this.entity.sprite.play("run");
    }
    else if(this.app.keyboard.isPressed(pc.KEY_A)){
        this.entity.translateLocal(-0.04, 0, 0)
        this.entity.sprite.flipX = true;
        this.entity.sprite.play("run");
    }
    else if(this.app.keyboard.isPressed(pc.KEY_W)){
        this.entity.translateLocal(0, 0.04, 0)
        this.entity.sprite.play("run");
    }
    else if(this.app.keyboard.isPressed(pc.KEY_S)){
        this.entity.translateLocal(0, -0.04, 0)
        this.entity.sprite.play("run");
    }
    else if(this.app.mouse.isPressed(pc.MOUSEBUTTON_LEFT)){
        this.entity.sprite.play("slash");
    }
    else{
        this.entity.sprite.play("idle");
    }
};

Hi @patrick_ramos!

You probably need to work with a boolean in combination with a timer or event to keep track of the time that’s need for the attack animation.

What do you want to happen if the user is trying to move and attack at the same time?

2 Likes

The update function refreshes the screen 60 times per second (at 60 FPS).
In other words, the update function is called 60 times.

It checks the if statement every time. Therefore, If the mouse is not pressed at least once during that, it transitions to the idle state.

I recommand refering to @Albertos’s reply and writing the code accordingly.

2 Likes