Topic was automatically imported from the old Question2Answer platform.
Asked By
timoschwarzer
Old Version
Published before Godot 3 was released.
Hello there!
I want to flip / rotate the entire stage with the player being the pivot.
I tried with rotating the Camera2D by 180°, which worked almost fine. The only problem I have is the ParallaxBackgrounds going crazy when rotating the camera. (I think they are rotating around global (0|0))
Is there a possibility to rotate the ParallaxBackgrounds and their Layers correctly? Or is there an even better approach to achieve this world-flip?
You can parent whatever you want to rotate to a Node2D (I’ll call it “NodeParent”) and rotate that Node2D to result in rotation of everything under it (children) rotated by calling NodeParent.set("transform/rot",angle). (angle is a var holding the rotate angle). If it is not rotating around the desired point (center in your case) you may change it with NodeParent.set("transform/pos",SomeVector2) where SomeVector2 is just a Vector2 var whose x and y members hold the translational offset. PS: Make angle and SomeVector2 into export members to have the pivot and rotation adjustable in the editor and accessible to animations.
Unfortunately, this doesn’t work with ParallaxBackgrounds since they are CanvasLayers and rotate around (0|0)
timoschwarzer | 2016-03-10 15:24
A really doozy way is to make that parallax node a child to a different Viewport rendering to a texture via .set_as_render_target(true) then have a sprite display that texture in the main visible Viewport (the one you are rotating). it will rotate with the camera just like any other sprite would.
Desired background image should be attached to it. In my case it’s “Sprite 2”.
Than in _process() of your Player’s script (for instance) you write code like following: