Reverse a Sprite without editing?

I have sprite animation of a player walking to right direction, but not to left.
Do I have to edit all the sprites?

(Credits to MInd Chamber)

1 Like
1 Like

Considering that you draw your sprite of a character walking to the right using

image(sprite, x, y)

You could also use this to get exactly the same result

image(sprite, x, y, sprite.width, sprite.height)

And, you could then simply reverse the horizontal size of the sprite by prepending a minus and then moving it to the right the same amount, to draw that character walking to the left:

image(sprite, x+sprite.width, y, -sprite.width, sprite.height)

So, then you could also make a function just for the direction:

def spriteDirection(sprite, x, y, dir):
  if(dir):
    image(sprite, x, y)
  else:
    image(sprite, x+sprite.width, y, -sprite.width, sprite.height)

where dir is True if you want the character going to the right, or False if you want the character going to the left.

2 Likes

maybe its a stupid question, but
this way I improve performance right?

Well, it matters on what you mean by performance.
Maybe making copies of your sprites mirrored would make it run just a tiny bit better because it wouldn’t have to scale anything and would be able to just copy it onto the screen as-is - but that would also obviously eat up some more RAM, and would be harder to manage than just straight up drawing the sprite mirrored.

3 Likes