Interface question

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rogerdv

In my game I have a camera that follows the player (lets say, like Hollow Knight) and I havent found a way to keep the UI in the screen. I thought that I should make it children of the camera, but anyway the UI elemnts sometimes move outside view. Whats the correct way to manage the UI in a 2D game?

:bust_in_silhouette: Reply From: mattkw80

Try sticking your UI in a Canvas Layer.

I had this issue on the weekend - when my player would run off the site of the screen - he would run away from the Health bar. I stuck the whole UI inside a Canvas Layer and now the UI stays in the view port.

Yes, that solved the problem! But now how can I make the lements resize with the screen? I dont see the green thingies in the corners.of UI widgets.

rogerdv | 2020-01-28 20:35

I think I know what you mean, and I’ll try to get your some reference on that.

mattkw80 | 2020-01-28 20:39

Which elements (nodes) are you using?

mattkw80 | 2020-01-28 20:54

I plan to use several images, labels, buttons, and recently fixed the joystick, which is composed by an sprite and a child TouchScreenButton.

rogerdv | 2020-01-28 21:32

Hey Sorry Roger, I’m trying to understand the resize the screen part… is your sceen size changing (zooming) in play, or do you mean - while making the UI, you are having trouble resizing the UI controls?

mattkw80 | 2020-01-28 22:10

I want to be ready for different resolutions, this is a game for cell phones, but I want to be ready for PCs with different resolutions too.

rogerdv | 2020-01-29 16:55

:bust_in_silhouette: Reply From: Merlin1846

Try attaching the UI to the camera, I know this is a little crude but it’ll work.