Topic was automatically imported from the old Question2Answer platform.
Asked By
GameSchool
Hi
In my game, I have a scene based on Canvaslayer, that I wanted to import in a different scene (Options menu scene in the main menu scene).
The problem is, that while most of the scene appear in place, the first object in the tree appear in an incorrect location. You can see an example in the image below (Sorry about the Hebrew in the UI itself) that there is a sprite in the right corner of the screen:
Note: In my PC it appears correctly, but in some other monitors it appears like that.
Update: I checked in the editor in a pc that show the scene incorrectly, and even in the editor, when changing the offset of the Canvaslayer, the change is working on everything but the first object in the tree of the Canvaslayer scene
I assume the problem is that a Sprite doesn’t inherit from Control, so it doesn’t play nicely with some of the standard control placement mechanisms (anchor, margin, …).
If your use of a Sprite is just to show a graphical element in the UI, you might be better served by a TextureRect instead. Unlike Sprite, TextureRect does inherit from Control and therefore will play nicely with other UI elements.
Thanks for the answer. Unfortunately it didn’t work, the results are the same
GameSchool | 2023-02-15 20:54
Do you see the problem when running the application on differing display resolutions? If so, I assume the problem is related to how the offending object is placed / anchored within its parent.
Can you share the layout of your scene tree (an image would be best)? Or, is the project itself available somewhere for inspection?
jgodfrey | 2023-02-15 22:14
This is how the scene looks like (canvas offset is (0, 0), but the offset set the position of all the objects, and it’s working correctly in multiple rresolutions):
The layout looks like that:
In the main scene it looks like this (Canvas offset is changed, and all the objects but the first on the scene tree apply to it). Note that in my PC changing the offset change the position of all the objects:
Update: When I entered the options menu to a completely empty scene, it worked as expected, but when I added another object to the scene tree (I tried canvaslayer, sprite2d and texturerect) is started to appear like in the example above.