|Topic was automatically imported from the old Question2Answer platform.
Im trying to implement a basic antagonist in my 2D game, but I have a doubt: how to flip the whole scene, not just the sprite. The scene contains also an area2d to detect the player when it is in front of the NPC, when the NPC looks from one side to the other, the area should flip too. How can i do this?
You need to structure the scene so the
Sprite and the
Area2D are in some common parent container (like a
Node2D, for example). Then, rather than just flipping the sprite, you need to flip the parent container. With that hierarchy, all of the children will follow along.
If you make your parent a
Node2D, you can “flip” everything by changing the transform’s x-scale between
scale.x = -1 # flip everything over
I dont have the project right here, but I think my parent node is a KinematicBody2D. So, I guess I should add a child Node2D and place the animated srpite and the Area2D there.
rogerdv | 2020-02-06 19:26
Yeah, it sort of depends on your scene structure. The important thing is that everything that needs to flip be somehow parented together. Then, you just manipulate the parent and the children follow along.
Really, any combination of these hierarchies should work:
Sprite <-- manipulate this
Area2D <-- manipulate this
Node2D <-- manipulate this
The critial part is that you manipulate the parent container…
jgodfrey | 2020-02-06 20:12