Hello Guest

Author Topic: Clarifying different devices and resolutions support  (Read 11344 times)

Finnegan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Clarifying different devices and resolutions support
« on: June 09, 2013, 11:50:58 am »
Sorry for another-one-resolution-thread, but I'm still confused after reading previous ones.

I'm migrating from cocos2d-iPhone where I used 3 sets of sprite atlases:
  • 1x: old iPhones 480x320
  • 2x: iPhones w/ retina 960x640, iPhone 5 1136x640, old iPads 1024x768
  • 4x: iPads w/ retina 2048x1536

Cocos2d has "points": one point equals 1 pixel on an old non-retina screen and 2 points on a new retina screen. So, iPhone/iPod touch screen size is always 480x320 points (568x320 for iPhone 5) and iPad screen size is 1024x768 point, regardless of DPI. All assets for iOS games were made 4x for iPad retina (with common divisor 8 to have accurate scaling) to and then scaled down with TexturePacker to 1x and 2x sprite atlases.

But for cross-platform development I have to deal with all these resolutions plus some less popular (and sometimes unpredictable for Android).

I'm using tk2dCamera that scales content according to the resolution and Multiplatform Toolkit that positions and scales content by looking at the aspect ratio or platform. I'm not stretching sprites in games, but show larger pieces of the game world (when it's scrollable) or make some sort of letterbox (additional parts of background, more spacious GUI, etc.).

And I can't understand how to do the following things right.


Atlases for different DPIs
2d Toolkit has platform specific sprite collections and as far as I understand it is the same idea as I described above for cocos2d. But another method with mipmaps and changing quality settings is described in this thread.
I'd like to use the latter method for smaller game file size. But will resizing textures on the fly significally increase loading time of every scene? Is Unity capable of quality downscaling of 2d art? (not pixel art)

Scaling down on the fly
Since I can't include sprites for every possible resolution, most of the time they will be scaled down (e.g: 4x sprites made for 2048x1536 will be scaled to 1600x1200 or 1920x1080). If I'm getting it right, all I need is a right setting for each resolution in tk2dCamera.

Relative positioning
It's simple for GUI with Multiplatform Toolkit, but I can't understand how to move dynamic objects in different DPIs and ratios.
Is tk2dCamera always counting 1 pixel for 1 Unity point and do I need to calculate positions and movement relating to DPI (multiply them by 1x-2x-4x)? Is scaled down content (by tk2dCamera, like from 2048x1536 to 1600x1200) not affecting pixel-to-points, but only physical size on the screen?

upd: the answer from this thread is "no, 1x, 2x, 4x sprites will all be physically exactly the same size, so distances will still be the same".
As far as I understand, I should work with points in 1x size and then despite 2x or 4x or other custom multiplier, my sprites always will use 1x point system. So I need to set up GUI and game world visibility for the lowest resolutions for all aspect ratios and then tk2dCamera will help me to scale it up using bigger sprites.
« Last Edit: June 09, 2013, 12:03:14 pm by Finnegan »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #1 on: June 09, 2013, 12:15:13 pm »
1. Atlases for different DPIs
Mipmaps aren't usually any smaller than platform collections - certainly not in memory at any given time. It doesn't resize on the fly when using that - just drops the top mipmap. If you don't have assets for individual resolutions, then work at highest res and enable mipmaps. That is the easiest option. The quality of downscaling in Unity depends on your art style. Sometimes its acceptable, sometimes not.

2. Relative positions.
Are the same at all resolutions / DPI / ratios / etc. Once you figure this out, everything becomes a lot easier, as you only really need to reposition / realign things that genuinely need to change.

Your last assumption is more or less correct. Sprites will always be the same size, so relative offsets between sprites, etc. will always be the same. You won't have to tweak those unless you actually need to for some reason.

Finnegan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #2 on: June 09, 2013, 07:56:56 pm »
Thank you! Got it except for resizing.

Let's say I have only 1024x768 background in my assets and want to show it on 640x480 screen without creating smaller assets or mipmaps. Could I achieve it with tk2dCamera override? (I'm now playing with its settings, but can't get this kind of scale.)

And is it possible to exclude 2x/4x assets from some builds? Maybe with help from Multiplatform Toolkit?
« Last Edit: June 09, 2013, 08:31:08 pm by Finnegan »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #3 on: June 10, 2013, 11:11:36 am »
The tk2dCamera can scale for that with just the default override. Native resolution = 1024x768, editor resolution =640x480 with the default override would do just that.

Excluding assets from builds isn't built in, but you can actually do it if needed. In the Resources/tk2d folder, you'll see a bunch of asset files. What you need to do, is go through them, and delete the ones you don't want. Each of these poitns to a loadable asset at runtime - so if you don't want 2x, delete all files which link to 2x assets. Or move them out of the folder - that might be a better solution than deleting them.

Finnegan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #4 on: June 15, 2013, 09:39:38 pm »
Sorry, more questions arised.  ::)

1. If my artwork is pixel perfect for 1136x480, 960x480 and multiple other resolutions, which one should I write in "Native resolution" fields?

2. If I have 1x, 2x and 4x assets, should I use 3 different cameras for them?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #5 on: June 15, 2013, 09:47:09 pm »
How are you setting up your game? Do you have multiple sprite collections? What are your images? How you'd set it up depends very much on your data.


2. No, they will all be the same physical size - same size, 2x or 4x more detail. No need for multiple cameras.

Finnegan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #6 on: June 16, 2013, 10:05:17 am »
I'm using MultiPlatfrom Toolkit and want my game to work on all popular aspect ratios: 3:2, 4:3, 5:3, 16:9, 16:10.

I have multiple sprite collections:
* 4x (2048x1536 iPad retina and other very large resolutions)
* 2x (1024x768, 960x640, 800x480 and other popular medium resolutions)
* 1x (480x320 old devices)

For resolutions "between" 4x and 2x (or 2x and 1x) I will scale down larger assets with tk2dCamera override (for example, 4x assets which are pixel perfect at 2048x1536 will be scaled down for 1600x900).

My immovable backgrounds (like menu background) will be large for preventing letterboxes at different aspect ratios. And for movable backgrounds like game field I'll just show more content (it's a top-down game). GUI is anchored to screen corners.

I see overall algorithm like this:
  • detect an aspect ratio of the device
  • detect resolution
  • choose 4x, 2x or 1x assets depending on resolution (tk2dSystem.CurrentPlatform)
  • choose right camera to have right scaling for current resolution and aspect ratio

I was thinking about multiple cameras because of different native resolutions for different sprite collections. But I also have different aspect ratios and complicated situations like "fit camera with 4:3 native resolution in a smaller resolution with 16:9 aspect ratio" when I can't use pixel perfect override (because sprites will be too large) or fit visible override (because some content will be cropped).

My main task is to make an adaptive design that will fit all 6 popular aspect ratios by:
* choosing right sprite collection
* scaling sprites down if it's not "native resolution"
* anchoring GUI elements
* showing different amounts of game content
« Last Edit: June 16, 2013, 11:56:30 am by Finnegan »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #7 on: June 16, 2013, 03:05:48 pm »
The one advantage of the tk2dCamera, is that the sprite size is fixed (1 pixel = 1 unit) regardless of resolution by default. You don't need multiple native resolutions. You can scale appropriately to handle this seamlessly. I suggest trying the "scale" parameter on the override to try and figure out how this works.

Your needs aren't exactly straightforward, so you will need a bit more robust understanding of how all of this factors in with each other. Work out the manual scale override parameter, and you should have yourself a solution there. Also, look into the source code to work out how everything is scaled. Eg. if you're scaling from 960x640 -> 1136x640, you could replace the background image, anchors, etc. and then keep the override as "fit height" and it will show more information horizontally. It is very very powerful, but you really need to spend the time to understand it.

MaaS

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 39
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #8 on: June 17, 2013, 11:14:08 am »
From time to time a post like this appears... and although I read all of them, I still dont quite get it...

I have the same requeriments as Finnegan (3:2, 4:3, 16:9 and 16:10 ratios, 1x,2x,4x collections for the same group of resolutions, where whenever I can, I would like to show "more world" without streching)... surely every multiplatform/mobile/tablet development have more or less the same specificactions as Finnegan and I have...

And the documentation is alright covering multiple sprite collections, but I miss an example mixing everything up to work on this kind of multiresolution/multiple ratio enviroment...

I would add to the actual multiple sprite collections documentation something like :

- anchoring GUI elements and/or different anchors-set's for diferrent ratios (a button placement could be ok on a phone but not on tablet)
- correctly setting up tk2dcamera overwrites for showing different amounts of game content, pixel perfect scaling... and things like that.
- moving the tk2dcamera around and putting limits to its movement (like world limits) when I have tk2Dcamera overwrites...

More or less everything up there can be found searching the forum but it would be useful if condensed on one doc.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #9 on: June 17, 2013, 11:39:16 am »
Yup, definitely.
That is being worked on now, next in line after the whack-a-mole tutorial. There will be pictures. Pictures explain so much better than words.


Finnegan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #10 on: July 05, 2013, 08:38:53 am »
Well, I defeated the problem.  8)

Step 0: add wildcard "fit visible" override to your camera
Step 1: find the aspect ratio
Step 2: set camera's native resolution for this aspect ratio (mine are 480x320 3:2, 512x384 4:3, 568x320 16:9, etc.)
Step 3: choose 1x/2x/4x by looking at device resolution

I hope, the very last question: where can I get the camera's current scale ratio to match the input? There's "scale" in UpdateCameraMatrix() but it can't be accessed outside the function.
« Last Edit: July 05, 2013, 08:40:31 am by Finnegan »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #11 on: July 05, 2013, 09:01:20 am »
Scale isn't public because it can possibly be non uniform.
What do you need the scale for?

The new tk2dCamera, has ScreenExtents and NativeScreenExtents to give you coordinates at those rectangles. Maybe that'll help?

Finnegan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #12 on: July 05, 2013, 10:12:52 am »
When I'm overriding with a smaller or larger resolution (e.g. 960x640), my sprites are still using the native one (480x320) for positioning.

So I'm getting an input of (900; 600) near the top right corner, but my top right sprite assumes it position is (450; 300). If I knew the scale, I would divide my input by it.

Sorry, I can't get what the screen extents are for.  :/
Quote
Returns screen extents - top, bottom, left and right will be the extent of the screen
Regardless of resolution or override

I got x:-19.8 y:480 w:360 h:-480 for native resolution 384x512 scaled up too 600x800 screen.
« Last Edit: July 05, 2013, 10:17:49 am by Finnegan »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #13 on: July 05, 2013, 12:51:20 pm »
I think you're missing one step there - Camera.ScreenToWorldPoint on your mouse will give you mouse at the correct coordinate space which you can just use relative to the sprites in world space. No need to guess anything, or even care about the scales.

Finnegan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Clarifying different devices and resolutions support
« Reply #14 on: July 05, 2013, 01:54:42 pm »
Thanks! I'm still a huge noob in Unity.  ::)