This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I just want to know if there is a way to display the parallax between other sprites. My game is basically a fish that eats flies. As such, I need the fish to be displayed behind the parallax so that it looks like its underwater, while the flies are above it. I've tried adding the player to a CanvasLayer and setting its "layer" property to -2, but it causes a weird bug where the Camera2D attached to its center moves along but can't keep up with the fish speed, which wasn't a problem before they were both added as children of the CanvasLayer. I then tried making a custom camera, which was updated each frame by:

func updatecamera():
var canvas
transform = getviewport().getcanvastransform()
transform2 = -getparent().position + Globals.screensize/2

Very simple stuff. Still the camera starts falling behind the fish, which makes me think the transformations must be also applied to the CanvasLayer or something...

Please help.

Bug explanation, CustomCamera code and Node tree:
Code and tree

in Engine by (13 points)

2 Answers

0 votes

i think easiest solution is to move down your fish or move up your parallax in the tree

by (106 points)

What you mean? If you mean taking fish out of CanvasLayer and ordering it bellow the parallax, this wont work because layers are rendered always before or after sprites. Thanks for the suggestion though.

0 votes

try this, get rid off canvas layer then follow the next tree structure


main is gonna be parent scene, parallaxbackground is gonna be child of main and fish, parallax layer and the flies are gonna be children of parallaxbackground

by (106 points)

This has worsened the issue, now fish and fly move in the same velocity in relation to the background (meaning that fish cant get close to fly) and the camera is still bugged and cant keep up... I also tried adding fish and fly as children of parallaxlayer, respectively before and after sprite, but that didnt work either.

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.