- Home /
How to adjust positions of the sprites to different screen factors?
Hi,
I'm creating a 2D game with sprites located evenly on the bottom of the screen. Everything works fine until I test the game with different aspect ratios: the sprites are no longer spaced evenly because the size/resolution of the screen changes.
I know I could check the screen size and position the sprites using a script but I'm wondering if Unity has any built-in functionality to keep the sprites "anchored" regardless of the screen resolution and the aspect ratio. By "anchored" I mean that when a sprite is at 2/3 horizontal distance, it remains at 2/3 no matter the aspect ratio of the screen.
Thanks, Leszek
Answer by MaxGuernseyIII · Oct 18, 2017 at 08:34 PM
That certainly exists for GUI elements. I'm aware of no such built-in thing for sprites that aren't being hooked into the GUI (as with an Image).
Are these sprites actually part of a GUI layer? If so, you could switch over to using Image and get the kind of anchoring you want.
NGUI might have a feature like that and I don't think it uses the traditional GUI infrastructure.
If all else fails, it probably wouldn't be that hard for you to write a single unity behavior called something like "ManagePositionAndScaleByScreenSize" that encapsulates the concept you just mentioned (tracking resolution and dealing with it yourself).
Answer by ata6502 · Oct 19, 2017 at 09:10 PM
Thanks Max for your answer. My sprites are a part of gameplay. They have colliders etc. They are not hooked into the GUI.
Writing a Unity behaviour is a good idea. I will go for that.
Your answer
Follow this Question
Related Questions
How to get native resolution of mobile devices 0 Answers
Unity 2D targeting multiple screen sizes 1 Answer
Sprite in different aspect ratio 0 Answers