How to make a button for cell phones?

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

Hi!

I need buttons for a cell phone game I’m making, but I couldn’t get any that work at all.

I tried to use a TouchScreenButton but my game uses a camera, and it seems that if you use a camera and you change the zoom, the shape of the TouchScreenButton changes in size and position. If you know any solution to that I would be grateful to know.

I also tried using Controls and creating my own button with the “gui_input” function, but it seems that when there is more than one finger touching and I take out them, it only sends the signal for the one who touched the Control first.

If you know another method to make a button on a cell phone or know how to fix my attempts to make it, I would be very grateful to know.

:bust_in_silhouette: Reply From: MikeSundaysGameDev

TLDR: Put the touch screen button and all your UI inside a canvas layer node(if you want more info on why you need to do this read the rest of the answer)

Every viewport, which is what the player sees in the screen, is comprised of canvas layers, each with a transform relative to the viewport. The camera 2d works by changing the transform of the base canvas layer, so if the camera would zoom it would "scale up"this and thus the touch screen button as well. So the only thing you need to do to fix this is put the touchscreen button inside a new canvas layer.

I hope it helps,