• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AceOneFlow · Aug 02, 2016 at 08:24 PM · scalingscreen resolutioncompatibility

How can I make my mobile game compatible for all screen sizes?

So I am working on this mobile game and I need to spawn some sprites in 4 different areas of the screen, specifically the ones created by drawing the 2 diagonals of the screen. I need to display the sprites in a certain order to form words that can be read from left to right for the top and bottom words and top to bottom for the words on the left and right hand side of the screen. The only problem is that when I try to Instantiate the sprites, I can't spawn them in the same place for different screens. For example, when I am testing the app on my computer through unity remote, the height of the screen is 600 pixels and I can display the top word by filling Screen.height - Screen.height/10 for the Y coordinates, and it is fine, bun when I build the app and run it on a physical device, where the height of the screen is 1920, or any value bigger than 600, everything gets messed up. I will post below an example of my problem, with pictures. So, let's focus only on the word that is supposed to be displayed at the top(i have some additional text lines in the game so I know that the word is displayed correctly) since I think that if the top word can be fixed, the others can be fixed too. This is how the top word should look like on an actual device:

alt text

It should be displayed somewhere in that area, where that P sprite is ( I made the game display all the sprites for a word one on top of the other so I can deal with the position on the X axis later). To get this result, I am setting the Y coordinate at Screen.height/2 + Screen.height/8 . I can't say exactly why I am using this value...it just seems right for it to be there. This is how the game looks on my computer, on a 600 px tall game view, with that value for the Y coordinate: alt text

If I want the word to be displayed correctly in my game view on my computer, I am using Screen.height/2 + (Screen.height/11*4), which makes the top word vanish if I build the game and run it on my phone ( a Oneplus One, if it matters), the word having its Y coordinate too big, going out of the frame. How can I fix that? What I've done so far, after spending at least 30 hours on this problem: I made a method called myPosition, that returns a Vector3 with the position at which a sprite should be spawned and I am using that position when I am instantiating the prefab. This is the method:

 Vector3 myPosition(int direction, int letterIndex,int length)
     {
         Vector3 final = new Vector3(Screen.width/2,Screen.height/2,0);
         float space=0;
         switch(direction)
         {
             case 0:
                 {
                     final += new Vector3(0, Screen.height/11*4, 0);
                     space = Screen.width / Letter.GetComponent<Transform>().localScale.x;
                 }break;
             case 1:
                 {
 
                 }
                 break;
             case 2:
                 {
                     final -= new Vector3(0, Screen.height / 8, 0);
                 }
                 break;
             case 3:
                 {
 
                 }
                 break;
         }
         return final;

Let me explain my logic now. The direction parameter indicates wether I need to get the position for the top, right, bottom or left word, by having the values 0,1,2 or 3. The letterIndex is quite obvious and the length parameter is the length of the word, so I can determine how much space to leave between the sprites. I have figured out a mathematical equation that can position all the letter correctly on the screen, on the X axis and also on the Y axis, for the left and right words, but it only works on that 600 px tall game view on my computer and on my phone, the sprites are scattered everywhere and most of the times I can't see any of them because of the space between the letters. I have also though about storing the most common screen resolutions in 2 arrays for width and height and then storing the X and Y values for the words in another 2 arrays, but I want the game to be compatible with every device.

right.png (222.8 kB)
1.jpg (117.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D Gameobject Location and scaling in different screen size(mobile) 0 Answers

Screen scaling problem 1 Answer

Sprite renderer scaling 0 Answers

Streched Texture when scaling cube 0 Answers

Scale UI Text 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges