2D Toolkit Forum

2D Toolkit => Support => Topic started by: test84 on December 01, 2013, 08:01:16 pm

Title: Does 2D toolkit support multiple resolution support for mobile?
Post by: test84 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.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware 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
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: test84 on December 02, 2013, 02:17:30 am
You guys are so awesome!
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: test84 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 ?
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware on December 02, 2013, 06:13:07 pm
No there isn't at the moment. You will need a script to handle this.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: test84 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?
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: Clet_ 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
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: test84 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.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware 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)
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: test84 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.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware 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.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: aaron7090 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";
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware on December 04, 2013, 10:40:45 pm
Can you switch platforms in the editor from the preferences editor?
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: aaron7090 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";
}

}
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware 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.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: aaron7090 on December 06, 2013, 12:34:36 am
The preference's platform switcher is showing the correct sprite for 1x, 2x and 4x. SetPlatform is running first under script execution order.

edit: ok it looks fine if I have a scene before with the setPlatform script and then navigates to the second scene with the 2x graphic.. there must be a better way of doing it?
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware on December 06, 2013, 10:25:47 am
Is this just an editor thing? Its sometimes a bit hard to ensure everythings unloaded properly in the editor before starting the game, but it should work 100% in game.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: aaron7090 on December 07, 2013, 09:03:37 pm
Doesn't seem to be just an editor issue. I put the build onto the phone and the 4x graphic only appears if the scene before it has the setPlatform code run. I'm just going to throw a dummy screen at the start to set the platform.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware on December 07, 2013, 10:23:12 pm
Start runs after Awake. The sprites get initialised in Awake. You probably should change your init point to Awake and that should fix this.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: aaron7090 on December 08, 2013, 03:24:00 am
Ah that was it, thanks!
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: aaron7090 on January 06, 2014, 12:32:51 am
OK so this works the graphic changes but I think there is an issue?

I have a graphic that is 100x100 which is the 1x graphic.

Then I have the 200x200 which is the 2x graphic.  The graphic switches between the 1x/2x graphics fine but the issue is that the 2x graphic isn't any bigger even when I test in unity with the preferences. It seems to replace the 1x graphic but keep its small size.

I am using the tk2dsprite script for that gameobject.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware on January 06, 2014, 01:14:07 am
That is expected. The asset sizes are always the same physical size to avoid having to reposition everything when the platform changes. Think of it as changing the amount of detail.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: aaron7090 on January 06, 2014, 04:59:20 am
Oh okay.

I'm testing on a 800x480 resolution in unity using a image that is 300x200. That looks fine but on some devices the resolution is 1280x720 and the 300x200 image is too small. This 300x200 graphic is centered on the screen.

What's the best thing to do in this case? Should I just show/hided the appropriate sized graphic?
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware on January 06, 2014, 10:44:58 am
Have you looked at the tk2d camera override feature - this is meant to solve this very problem by rescaling the camera to fit. You design your game for one resolution, then have the override rescale it to fit other resolutions and aspect ratios. That totally decouples the 2 issues of resolution management, and detail management.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: 11pika11 on January 11, 2014, 01:57:54 am
Hey... just had a little project in corona sdk. they set the @2x and @4x with a "scale factor".
the scale factor is calculated simply by dividing the width of the "current device" by the width of "native resolutions.

Quote
600 / 320 = 1.875   --Kindle Fire & Nook
640 / 320 = 2.0     --iPhone 5
768 / 320 = 2.4    --iPad
800 / 320 = 2.5     --Kindle Fire HD / Nexus7
1200 / 320 = 3.75   --Kindle Fire HD 8.9
1536 / 320 = 4.8   --Retina iPad
(from corona sdk blog)

what they suggest is that if the scale factor is greater than 1.5 you should use @2x and if it is greater than 3 use @4x

so you could do this by using Screen.width in Unity and dividing it by the width of your native resolution (which you set up with tk2d)

hope this helps!

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

Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: tyapichu on January 14, 2014, 12:52:11 pm
Have you looked at the tk2d camera override feature - this is meant to solve this very problem by rescaling the camera to fit. You design your game for one resolution, then have the override rescale it to fit other resolutions and aspect ratios. That totally decouples the 2 issues of resolution management, and detail management.

can you explain what should i do if difference between planforms is in DPI? i've got a Tab with 1280x800 resolution 10.1 inches and a phone 1280x768 4.5. i set tk2dSystem.CurrentPlatform = "2x" on smaller device accordingly DPI. but camera stays the same. i can't use camera override cause matching by Resolution or Aspect doesn't mutch to me. so i have to change sprite size. may be you've got better solution.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware on January 14, 2014, 01:23:03 pm
1x and 2x textures are supposed to be 1x and 2x the size. Your difference is pretty minuscule isn't it? 768 vs 800. Why would you want to switch to a 2x texture on that platform?
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: tyapichu on January 14, 2014, 06:09:40 pm
the problem is in DPI. for example i have a button. it has size 64x64 pixel and on Tab with 1280x800 10.1 inch screen (DPI about 150) it is suitable for finger touch. but on phone with 1280x768 4.5 screen (DPI about 300) 64x64 button is more than 2 times smaller - it's not suitable for finger. i'm checking DPI on start of game and changing CurrentPlatform to "2x" if DPI is more than 250 so game will use 128x128 art for my button on phone. but sprite size stays 64x64 meters which are not good for phone. my button becomse 2 pixels per meter but camera stays 1 pixel per meter. i have two ways to solve this problem: 1) change camera size to 2 pixel per meter (not usable in runtime, didn't find haw) or 2) change sprite size and position checking current CurrentPlatform. so i used second way - by changing button size it becomed like 128x128 meters and suitable for finger. but i'm not shure this way is good enought. first way whould be better i think. or you have another way to solve my problem i didn't find.
Title: Re: Does 2D toolkit support multiple resolution support for mobile?
Post by: unikronsoftware on January 14, 2014, 06:22:53 pm
Use a custom override. Set the resolution, then set the scale to whatever you need it to be. If you want full control, remove all overrides leaving one - then change that from your own code. You can scale as you like based on your own logic