Figured out an alternative way to flip sprite. Wondering if there is a better way.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By independentCog
:warning: Old Version Published before Godot 3 was released.

Flipping a sprite on its y axis is fine when its symmetrical but when it comes to something that is asymmetrical it just doesnt add up. Example sprite holding sword and shield. Flipping will not show the sword and shield in the correct hands. What I came up with is this.

I put two sprites under the parent player node, one showing it facing left and one facing right. When hitting right input I use hide() on the left one and than show() on the right one, when hitting left input vice versa. This essentially means that I’ll have to have to double the amount of animations and call them appropriately based on input. For one test image this is fine but something tells me later on as a game grows more complex this could get hairy. Is this method fine or there a better alternative using the godot engine?

One possible idea I had was having the armaments whatever they are as separate objects that would change positions based on direction. This would mean less images to load at start but I also foresee some annoying bugs with that popping up.

Another thought I had was to load and delete the sprites dynamically, but I’m most likely over complicating this by doing so. Something tells me there a very simple way to pull this off that I’m just not seeing in my limited experience with this engine.

I’d be interested in hearing the communities thoughts on this.

:bust_in_silhouette: Reply From: Warlaan

What kind of animation are you using? If you are using sprite sheets you can just add another animation that accesses other parts of the sheet, thus allowing you to put all animations on one sheet.

I was going to use bones and ik on a cutout. I see what you mean, using a spritesheet would be preferable that way gpu would just load one large image once instead of referencing multiple and I can just declare a different region of the same image for each part. I just did this by using this in the script on my RidigBody2d:

#global var
var sprite_mod = null
#in _ready() so I can use sprite classes in ridigbody2d extend
sprite_mod = get_node("name_of_sprite")
#position of each region inside each correct if input statement

Thanks =) I tend to over complicate stuff.

independentCog | 2016-05-29 16:57

:bust_in_silhouette: Reply From: Peter

I used the code of the platformer example:

set_scale(Vector2(-1, 1))


set_scale(Vector2(1, 1))

for other direction.