Hello Guest

Author Topic: Does 2D toolkit support multiple resolution support for mobile?  (Read 17700 times)

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Does 2D toolkit support multiple resolution support for mobile?
« on: December 01, 2013, 08:01:16 pm »
Hi,

In Corona SDK you can set special extension for files like 2x and 4x and on runtime it will automatically select art asset based on resolution of device. Does 2D Toolkit have this feature?

So you basically make your game for 320x240 and do not worry about fragmentation or different resolutions.

Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #1 on: December 01, 2013, 08:39:55 pm »
You'd do that with platform sprite collections.
http://www.2dtoolkit.com/docs/latest/advanced/platform_specific_sprite_collections.html

And the tk2dCamera to scale correctly for different resolutions / aspect ratios.
http://www.2dtoolkit.com/docs/latest/reference/tk2dcamera.html

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #2 on: December 02, 2013, 02:17:30 am »
You guys are so awesome!

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #3 on: December 02, 2013, 02:24:58 am »
In the platform specific documentation you mentioned that we have to call

Code: [Select]
tk2dSystem.CurrentPlatform = "2x";
"based on various game logic".

So my question is, is there anyway for tk2D to automatically find out about which resolution the target device has and choose the asset version, i.e. 1x, 2x, 4x, etc, that matches it better than others, like is closer to in terms of resolution ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #4 on: December 02, 2013, 06:13:07 pm »
No there isn't at the moment. You will need a script to handle this.

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #5 on: December 02, 2013, 09:33:24 pm »
No there isn't at the moment. You will need a script to handle this.

Would you please guide me on how to write it?

Clet_

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #6 on: December 03, 2013, 04:30:54 pm »
As far as I'm concerned, we've always defined the platform throught pre-compilation commands such as:

#if UNITY_WEBPLAYER
tk2dUIManager.currentPlatform = "2x";
#elif UNITY_IPHONE
.
.
.


Note that the precompiled syntax is probably not exact, since I don't have my projects at hand and I wrote it as I remember, but you can get the feeling of it

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #7 on: December 03, 2013, 06:14:12 pm »
Thanks but it's way deeper than that. You have to find out resolution of the device and that's not enough because some tablets are low resolution and so their pixels are big and thus you have to find out PPI, pixels per inch.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #8 on: December 03, 2013, 11:07:50 pm »
Yup, and thats exactly why tk2d doesn't do it. Only you know what platforms you want to support. Eg. if you only care about iOS devices, you could pretty much hardcode everything, or have exactly the code you need for the devices you care about. (consoles, wii u second screen, mobile, etc)

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #9 on: December 04, 2013, 01:55:04 am »
But it's quite possible to handle situations that most people want for mobile. I mean engines such as Corona SDK do it and there are some Unity assets that do it as well and it's really strange, at least to me, to see that tk2d doesn't support such feature.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #10 on: December 04, 2013, 11:02:45 am »
I would love to add something to handle it automatically, but I really don't know what most people want. From my experience everyone seems to want something different.

aaron7090

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #11 on: December 04, 2013, 06:47:50 pm »
Sorry if this is a incorrect answer but wouldn't the solution for this be something like:

http://docs.unity3d.com/Documentation/ScriptReference/Screen-dpi.html

// random numbers, these arent realistic numbers i just made them up
const float HIGH_DPI = 100;
const float ULTRAHIGH_DPI = 150;

if  (Screen.DPI > ULTRAHIGH_DPI)
{
 tk2dSystem.CurrentPlatform = "4x";
}
else if (Screen.DPI > HIGH_DPI)
{
 tk2dSystem.CurrentPlatform = "2x";
} else
{
 tk2dSystem.CurrentPlatform = "1x";
}


I'm trying to do something like this in my current project but from testing this line of code doesn't do anything(I've set up the files and folders correctly and the 2x image is showing up in the editor by default - the 2x image only showed up in the editor after I compiled for android, seems like a weird bug?):

 tk2dSystem.CurrentPlatform = "2x";

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #12 on: December 04, 2013, 10:40:45 pm »
Can you switch platforms in the editor from the preferences editor?

aaron7090

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #13 on: December 05, 2013, 02:23:46 am »
I restarted Unity3D now it shows the 1x graphic by default. The script that I'm using that I've thrown on the tk2dUIManager doesn't seem to do anything:

Code: [Select]
using UnityEngine;
using System.Collections;

public class SetPlatform: MonoBehaviour {

void Start ()
        {
            tk2dSystem.CurrentPlatform = "2x";
}

}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Does 2D toolkit support multiple resolution support for mobile?
« Reply #14 on: December 05, 2013, 06:13:06 pm »
Does the preferences window switcher work for you? It could be that tk2d thinks  the sprite collection is loaded and isn't trying to load the correct platform. The prefs window switcher will verify that all the data is valid and working properly before we figure out why its not reloading.

Also - setPlatform is called before everything else right? The script execution order matters here.