Reputation: 2749
I'm trying my first steps with Unity's new 2d environment at the moment (coming from cocos2d). I'd love to have my game work on iOS / Android My question is: How can I position sprites pixel perfect / depending on screen size. E.g. have the menu button on the top left on the screen.
I'm parsing levels from XML files. In those files the positions of each sprite are determined. Where's the best point to parse that file and how can I create my level from that file?
Hope somebody can help!
Upvotes: 3
Views: 3707
Reputation: 235
make yourself a prefab with a simple script on it, and some exposed public variables... like clamp left, clamp right, clamp top, clamp bottom. Then in the script, in Start() it just moves that object to x=0 y=0 or x=Screen.width or y=Screen.height So you can easily just set the checkboxes to clamp this object to any edge of the screen (or corner)
Then when you make your own new sprites, just make the appropriate clamp object it's parent. mySprite.transform.parent = clampTopLeftObject.transform; Then no matter what device or resolution or aspect ratio, our gui sprites can be clamped to the screen edges however you see fit to arrange them :)
Upvotes: 1