Hello Guest

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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #15 on: July 28, 2014, 01:18:31 pm »
Yeah looks like it will do it. You'll probably need to change Screen.width depending on your needs but it should work.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #16 on: July 28, 2014, 02:12:15 pm »
Also, each time I commit a sprite collection I get a pair of errors (attached). They occur on every 2D Toolkit project I have made. Is it a known bug and will it affect my game in anyway?

I also had a shot at coding (it was bound to happen eventually) derived from the code that I found to identify the device through its width.

There is an issue with the <GameObject> part and I get an error saying:
Assets/Scripts/LoadCustomBackground.cs(11,40): error CS1525: Unexpected symbol `<', expecting `identifier'
I am trying to load the prefab sprites that I made for each background. How would I correct this error and are there any other improvements that you would make to the code?

Also, I guess with this code I would have to run it on every scene/level. Do you have any suggestions on how to make it run on the init scene simultaneously with the init script that I posted earlier, so that it would detect what device (and therefore what background sprite prefab to load) in the init scene and would automatically load the respective background for each scene/level automatically? Thanks.
« Last Edit: July 31, 2014, 11:04:39 pm by blazingriver »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #17 on: July 28, 2014, 02:40:16 pm »
Looks like a Unity bug. I don't remember seeing it, but it shouldn't affect your game in any way.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #18 on: July 28, 2014, 02:50:43 pm »
Looks like I edited my last post at the same time you posted your reply! :P Would you be able to have a look at the script I made to help reduce the memory overhead that you mentioned earlier and look at the questions I had about it?
Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #19 on: July 28, 2014, 03:28:44 pm »
It should be Resources.Load<GameObject>
not Resources.Load.<GameObject>

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #20 on: July 28, 2014, 05:01:50 pm »
Thanks, but now i get another error saying that unityengine.screen.width cannot be assigned to (it is read only)? And do you have any advice on automatically loading the right background without running this script in every scene?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #21 on: July 28, 2014, 05:51:15 pm »
= should be ==
in Screen.width =

You only need to do this once, this setting is permanent.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #22 on: July 31, 2014, 11:02:34 pm »
Ok, I have corrected the custom background script but I can't figure out how I would get it work or how I use it (despite the fact that I wrote some of it!) So I add the script along with the init resolutions script into an empty game object in a initialiser scene. I have the background sprite prefabs in the resource folder. The init scene instantly automatically loads to the first game scene and I should of already loaded the right prefab using the background script. However, how do I get the background sprite to appear? Essentially I am asking how I would get it to work :P I assume the script works fine, but am I missing something out, such as an additional script?  Would it be possible if you could walk me through getting the script set up?

Thanks again! :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #23 on: August 01, 2014, 09:08:52 am »
What is in your bg script right now?

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #24 on: August 01, 2014, 01:29:24 pm »
The same as before (with the corrections):
Code: [Select]
using UnityEngine;
using System.Collections;

public class LoadCustomBackground : MonoBehaviour
{
void Awake()
{
Application.targetFrameRate = 60;

if(Screen.width == 480) {
Resources.Load<GameObject>("Background_iPhone");
}
else if(Screen.width == 960) {
Resources.Load<GameObject>("Background_iPhone_4");
}
else if(Screen.width == 1024) {
Resources.Load<GameObject>("Background_iPad");
}
else if(Screen.width == 1136) {
Resources.Load<GameObject>("Background_iPhone_5");
}
else if(Screen.width == 2048) {
Resources.Load<GameObject>("Background_iPad_Retina");
}
Debug.Log("Device data:");
Debug.Log("Screen resolution: " + Screen.width + " x " + Screen.height );
}
}


And I am also getting this error (on an unrelated topic to the script that I posted above):
NullReferenceException: (null)
UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs)
UnityEditor.Editor.GetSerializedObjectInternal ()
UnityEditor.Editor.get_serializedObject ()
UnityEditor.MaterialEditor.OnEnable ()

It doesn't seem to have any effect on the editor, but I only get it when I use sprite collections.
« Last Edit: August 01, 2014, 02:47:43 pm by blazingriver »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #25 on: August 01, 2014, 07:10:31 pm »
You need to instantiate after Resources.Load...
Instantiate(Resources.Load...)

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #26 on: August 10, 2014, 04:50:56 pm »
Another question, is there a way to make it so that a sprite automatically scale their size, so that they look the same size on any device irrespective of their pixel density. What I mean is if you have a sprite (with 1x,2x and 4x iterations), which is a logo on a splash screen, if you load this on a iPhone 3gs, 4, 5, iPad and iPad Retina, the logo would have different sizes in their real life appearance (i.e. when you use it/ how it appears on their device). Is there anyway to overcome this?

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #27 on: August 11, 2014, 10:15:08 am »
1. The 1x, 2x and 4x sprites are all the same physical size.
2. The camera changes what you can see depending on resolution / override.

You can either scale the sprite to be the same size on screen on all devices, or change the camera override to fit vertical, or something like that.

blazingriver

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #28 on: August 17, 2014, 01:56:24 pm »
Thanks for your reply. From what I can see in the game view that seems to work. However, I will check it on my device later to confirm it. However, now with the override it scales the background up along with the sprite. Is there anyway to make the background exempt from the override since I am using custom device backgrounds instead?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mobile Resolutions and Screen Sizes?
« Reply #29 on: August 17, 2014, 11:11:59 pm »
Use a different camera for the background, thats the easiest way to go about this. Otherwise you'll have to perform the opposite transformation the camera does to get the background to scale to fit.