Hello Guest

Author Topic: Mobile Resolutions and Screen Sizes?  (Read 25054 times)

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Mobile Resolutions and Screen Sizes?
« on: July 19, 2014, 03:11:12 pm »
Hi,
I am fairly new to unity and especially new to the 2D toolkit so please forgive any of my mistakes. Also, I am sorry if this topic has been discussed to death (which I am sure it has), but I am having difficulty comprehending the instructions on resolutions and screen sizes given within the 2D toolkit's documentation. I know screen sizes and resolutions are two separate issue, which have to both be undertaken separately. Could someone give me a simple step by step guide on how to make a 2D iOS (the platform that I am targeting) game have a resolution compatible with all the different generations of iOS devices and platforms (e.g. iPhone/iPad/(mini)) and how to make the screen size adapt to the different devices (e.g. iPhone 5s and 3gs). I am familiar with the overrides discussed within the documentation but I am unsure how to specifically apply it to the resolutions. A step by step guide on both the resolution and screen size compatibility (to make it a universal app) would really be helpful since I am generally unsure about both topics.

Also, would I use the lower resolution of the 3gs or the higher resolution of the 5s or the resolution of the iPad as the native resolution?

Thanks in advance! (and sorry if anything I have mentioned is obvious, since as I mentioned, I am new to Unity so please forgive me :) )

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #1 on: July 19, 2014, 04:49:07 pm »
Start with 3gs resolution artwork. Add a tk2d camera with 1 wildcard override set to fit visible. It should work on all your platforms. Try the different things there on different device resolutions to figure out how they work. It should be pretty straightforward to understand when you see it working.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #2 on: July 21, 2014, 10:22:58 am »
I kind of get it now, thanks! However, I am still unsure on exactly how overrides work and how you use them. I read the documentation, but I am still unsure on how to apply the overrides. Does there happen to be any mobile 2D toolkit demos that have been developed so that they are compatible with all iOS device sizes and resolutions which I could look at or any (video) tutorials which investigate mobile compatibility of ratios and resolutions (such as the whack a mole tutorial but for mobile devices).

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #3 on: July 21, 2014, 01:06:18 pm »
There are no demos for this, everyones needs are different. You should really just try this with some images, all you need to do is switch the game window resolution to preview what it will look like on each device. Once you get the hang of what its doing with one override, switch the overrides to see what results you can get. Start with 1 tk2dcamera, with 1 wildcard override, set to fit visible.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #4 on: July 21, 2014, 04:26:44 pm »
Thanks for your reply! I have a few more questions (sorry!) First of all, is it possible to detect the platform the game is loading on so I can use this script as mentioned in the documentation "tk2dSystem.CurrentPlatform = "2x";" and its 4x and 1x iterations depending on the platform that is being used (could this be done through the override system?).

With the normal wildcard override (regarding the different screen sizes and aspect ratios), the background looked fine (non-streched) on all platforms other than iPhone 5 wide (16:9) and iPad wide (4:3) where it stretched. I tried to fix this by using another override (screenshot attached) but it didn't make a difference and it still uses the wildcard (it doesn't detect the aspect ratio). I know that I am doing something wrong but I can't figure out exactly what. Additionally on the iPad wide (1024x768) the background is letter boxed. How would you recommend to overcome both the stretching and letter boxing. Currently for the letter boxing I am using the fill override when it detects the 1024x768 resolution (but then some of the image is cut out since the background is enlarged to fill so I am open to other suggestions). Is it possible to provide and use separate background sprites depending on the detected aspect ratio so that there is no clipping on the iPhone 5 and iPad and so the background is designed to specifically fit that device? Also, what exactly do you mean by switch overrides (do you mean change the scale mode?).

Thanks once again! :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #5 on: July 21, 2014, 06:36:55 pm »
You will need to detect the platform, etc using Unity functions. There are many different ways of doing this, eg. detecting screen size, detecting device by name, etc. Check the unity forums / answers for more details on what you can do to detect this. The override system is specific to the camera, and doesn't tie in with the platform switching at all - the 2 systems are independent to one another.

If you switch to the General tab, it'll tell you that the tk2dcamera can't detect the resolution. In the game window, you should use a fixed resolution rather than an aspect ratios, or simply choose the resolution to simulate in Presets.

By switching overrides I mean change the scale modes mainly. The offset isn't really going to affect the result as much.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #6 on: July 22, 2014, 11:54:36 am »
When you say that the tk2dcamera can't detect the resolution, does that mean that you cannot use the resolution option under the "Match By" drop down to target specific screen resolutions? And if so does that mean the wildcard option is the only override choice? Under the general tab I don't get any warnings telling me that the tk2d camera can't detect the resolution.

Also is it possible to use custom, specific sprite collections (designed for specific device) depending on the devices resolution, to prevent letter boxing on devices with different aspect ratios (iPhone 5+ and iPads)? (That is, if the tk2d camera can detect resolutions?)

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #7 on: July 22, 2014, 01:50:27 pm »
About detecting the resolution - your game window screenshot shows you've set the size to iPhone 5 Wide (16:9). This is what we can't detect. Set the resolution to a fixed number, and everything will work a lot better.

The sprite collection switching only supports 1x, 2x and 4x sizes.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #8 on: July 22, 2014, 03:07:55 pm »
There is one more question that I have about overrides. With the resolution system included in the toolkit is it possible to reposition the various different elements of the scene (e.g. the GUI and possibly sprites) so that they move to the corner or closer to the side of the screen etc?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #9 on: July 22, 2014, 03:43:42 pm »
You can use tk2d Camera anchors to do that.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #10 on: July 22, 2014, 05:02:16 pm »
I just had another thought, could you not load the game with all the different sprite backgrounds specifically designed for each of the targeted platforms (e.g. one designed for the iPhone 5, iPhone 3gs/4/s, iPad) and then detect the device's platform and hide all the other sprites/backgrounds leaving only the respective background for that device showing? It may not take full advantage of tk2d's resolution and override features but do you think that it could be a potential effective strategy?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #11 on: July 22, 2014, 05:19:40 pm »
If you do that in Unity, you'll have the memory overhead of every single one of them. One way to do it is to load the correct background at runtime using Resources.Load to load the correct prefab.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #12 on: July 22, 2014, 06:41:26 pm »
Do you know if such a thing could be done with playmaker using their actions instead of through scripting, since I am relatively new to coding?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #13 on: July 22, 2014, 07:01:28 pm »
Sorry, I don't know enough about playmaker to tell you that. Maybe someone else will be able to help you - it might be worth asking on their forums as well.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #14 on: July 28, 2014, 10:41:56 am »
Thanks for all your help so far!
I found this script:
Code: [Select]
using UnityEngine;
using System.Collections;
 
public class Main : MonoBehaviour
{
void Awake()
{
Application.targetFrameRate = 60;
 
if(Screen.width > 1136) {
tk2dSystem.CurrentPlatform = "4x";
}
else if( Screen.width > 480 ) {
tk2dSystem.CurrentPlatform = "2x";
}
else {
tk2dSystem.CurrentPlatform = "1x";
}
Debug.Log("CURRENT PLATFORM (main) : " + tk2dSystem.CurrentPlatform );
Debug.Log("Device data:");
Debug.Log("Screen resolution: " + Screen.width + " x " + Screen.height );
 
Application.LoadLevel("Game");
}
}

Source: https://gist.github.com/AdamDrobotij/10770946#file-2dtoolkit-main

Would you say that this would work to help set and apply the 1x, 2x and 4x textures? I wouldn't know since I am not familiar with programming, but does it look alright to you? Would I simply make an Init game object and give it this script and would it work? (if i change the Application.LoadLevel scene to my own scene).

Nevermind, I just realised it does work! I just made a little mistake while adjusting it.
« Last Edit: July 28, 2014, 02:04:58 pm by blazingriver »