Hello, so you know those games where the HUD is offscreen but shows up on screen when you collect stuff? Like let’s say you collect a coin, the coin icon and number would show up and go back offscreen if you don’t get another coin for a few seconds, and the life icon shows up when you get an extra life, I also want when you a press a button it makes the whole HUD (Coins + Lives) show up.
Here’s an image to demonstrate.
I tried to do this with tweens, but always something would go wrong, either it would keep moving left/right the more you collect/press the key, I tried putting various conditions like X position of LifeHUD/CoinHUD, opacity, tween playing and such and all of them break something after a while and have it not work, what’s the best way to do this?
Put the HUD on a separate layer, or layers if you want them to move in different directions at the same time. Them move the camera of that layer in the opposite direction to how you want the objects to move.
The camera’s position is in the game world/scene. On screen however, it’s always in the middle. My rule of thumb is to move the camera a screen width or height away. If you tween it, you can start fast and stop smoothly.
To visualise it better, take a mobile phone and put it over a larger picture. The larger picture is the HUD and the phone is the HUD layer camera.
Thank you! It was a hassle to get the exact positions, but in the end it worked, it’s much better tweening the camera than the X/Y positions of the HUD elements themselves