+3 votes

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?

Best regards!

in Engine by (711 points)

4 Answers

0 votes

I think you can rotate the currentscene for getting it you can get it using get_tree().get_current_scene()

by (580 points)
edited by

But doesn't it rotate around (0|0)?
Thank you! I'll try when I'm back home...

Dont forget to use backquotes (`) when writing code snippets, so that the underscores are not interpreted as italic tag, see http://godotengine.org/qa/1016/how-to-write-underscore-_-in-comments?show=1016#q1016

I fixed it here though :)

0 votes

You may prevent the rotation of the parallax background by ticking the option "unfollow camera" (I don't remember the exact name). I hope it helps ;-)

by (109 points)

There is only "Ignore Camera Zoom" for the ParallaxBackground

Yep, that's it! But I guess you might want your parallax to rotate as well... Not a good solution I suppose.

Isn't it possible to flip the entire viewport by 180°?

0 votes

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.

by (44 points)
edited by

Unfortunately, this doesn't work with ParallaxBackgrounds since they are CanvasLayers and rotate around (0|0)

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.

0 votes

Try to add CanvasLayer with negative Layer value:

enter image description here

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:

get_parent().get_node("CanvasLayer/Sprite 2").set_rot(-get_rot())

So you just attaching inverted Player's rotation to your background.

by (14 points)

Or you can get current rotation of camera instead of player's rotation depending on your game design.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.