How do you flip an object with arrow keys

Hi im trying to make my game character flip in the direction of the key I press. I also want it to stay in that position even after I let go of the key. How do I do this?

Hi @Animator786,

To flip a character, you can use the clip.flipX and clip.flipY properties.

Here’s some code that does this.

function keyDown(key) {
    if (key === "RIGHT") {
        this.flipX = false; // Flip the character back to normal if needed 
        
        this.x += 5; // Move the character to the right
    } if (key === "LEFT") {
        this.flipX = true; // Flip the character if needed
        
        this.x -= 5; // Move the character to the left
    }
}

And here’s a project with the code on an object!

FlippingCharacters-Jan1-2019-10.20AM.html (790.4 KB)

Happy New Year!

Hey thanks.

Happy New Year to you too!