Hello Guest

Author Topic: Multiple Sprite Sizes  (Read 6046 times)

larryapple

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Multiple Sprite Sizes
« on: June 06, 2013, 08:19:12 pm »
I am doing a monster bubble popper with multiple numbers of columns, from easy to hard. So on an iPad at 5 columns, the sprites are very large. On an iPhone at 10 columns they are quite small. I am using artwork at about 300 x 300 pixels, with no anti-aliasing in the originals, and a small number of colors in each sprite. So far the sprites look surprisingly good on all devices. I am using world coordinates and adjusting the sprite sizes on the fly, and the default target height of 640.

Since the game is always in portrait mode, I suppose I should choose a target height of 960 to get best results on iPhone, and its probably close enough to 1024 for iPad. Then for retina displays and Android devices with more pixels I could use 1920.

So far I am getting identical results with either a perspective camera at 78 or an ortho camera at 8. I presume those will change if I change the target height, no problem. Do you have any suggestions on how to proceed, or am I on the right track?
« Last Edit: June 06, 2013, 08:25:04 pm by larryapple »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Multiple Sprite Sizes
« Reply #1 on: June 06, 2013, 09:53:56 pm »
Get it pixel perfect at one resolution first, changing that to work at other resolutions is fairly straightforward.

Note: With a perspective camera, the size depends on the distance to the camera so a number like 78 (I'm guessing that is FOV) is pretty meaningless on its own, without considering the distance of the sprite -> camera.

To get it pixel perfect on the iPhone4 portrait, set the target height to 960. Pick an ortho size and stick with it - use the same ortho size on the orthographic camera, AND the sprite collection. Your sprites will now be pixel perfect at when running at that resolution / device. An orthographic camera will also scale to fit the height when running on other devices, by default. When running at 768,1024 - the game will be centered, and there will be a little bit more information visible around the left and right sides.

That will be a good place to start.

larryapple

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multiple Sprite Sizes
« Reply #2 on: June 06, 2013, 10:49:17 pm »
But now I am using all of the real-estate on the device regardless of aspect ratio, by scaling the sprite size to the actual screen width divided by the number of columns chosen. To me, this is much more desirable than having useless margins on the iPad. And then my other question, since I am scaling the sprites dynamically, won't this break pixel-perfect anyway?


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Multiple Sprite Sizes
« Reply #3 on: June 06, 2013, 10:57:08 pm »
So you're scaling the sprites non-uniformly?

larryapple

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multiple Sprite Sizes
« Reply #4 on: June 06, 2013, 11:49:55 pm »
No. I am adapting to the width of the device, whereas Unity adapts to the height. Then for narrow devices, I might have room to add another row or two of sprites, still leaving a UI area above and below the sprites.

So if I understand correctly, I can scale the sprites uniformly and they will be pixel-perfect if I use the height of the target screen?
« Last Edit: June 07, 2013, 12:25:38 am by larryapple »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Multiple Sprite Sizes
« Reply #5 on: June 07, 2013, 09:19:39 am »
Sorry, no.
The sprites will be pixel perfect (1 pixel in sprite mapping to 1 pixel on screen) if you use the target height, and display at scale=1.

When changing resolution and aspect ratio, the easiest thing to do is to change the orthographic size on the camera to compensate. By tweaking this, it'll be possible to make it pixel perfect at the new resolution without changing the scales of any of the sprites. If you want to re-layout on this new resolution, you're fine to do that too :)

larryapple

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multiple Sprite Sizes
« Reply #6 on: June 07, 2013, 05:07:52 pm »
Oh, I finally "get it".


larryapple

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multiple Sprite Sizes
« Reply #7 on: June 07, 2013, 06:47:56 pm »
Well, now I am completely baffled. I set the collection settings to target height 960, ortho size 5, use tk2dCamera. When I click the check mark, the values disappear. Why is that? I also tried other sizes.

I have a setup scene where I create a single sprite from that collection and place it in the center of the screen. It is about 280 pixels square. Now no matter what I do to the tk2dCamera size, nothing changes. The only way I can get it to change is to "Force Editor Resolution".
« Last Edit: June 07, 2013, 06:59:03 pm by larryapple »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Multiple Sprite Sizes
« Reply #8 on: June 07, 2013, 07:06:03 pm »
Its mutually exclusive. You either use an orthographic camera, or use a tk2dCamera. You can't use both at the same time.

Set the collection settings to 960, ortho size 5. Commit.
Create a unity camera, change to orthographic and set size to 5.
Now when you create that sprite from the collection above, it will be pixel perfect at 640x960.


or...


Set collection size to "Use tk2dCamera". Commit
Create a tk2dCamera (Create > tk2d > Camera).
Now when you create a that spritee, it will be pixel perfect in the tk2dCamera.

larryapple

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multiple Sprite Sizes
« Reply #9 on: June 08, 2013, 05:47:08 pm »
Now the monsters are drawing well, and I'm working on a UI panel similar to your demo. Currently I am using EasyTouch for the monsters (to destroy them), and when the panel is called up on top of them they still get the message. I am checking to see if it is in panel mode, but I would like to avoid "dueling touches". Do you have any suggestions?

« Last Edit: June 08, 2013, 08:25:33 pm by larryapple »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Multiple Sprite Sizes
« Reply #10 on: June 08, 2013, 10:24:36 pm »
Create a massive invisible background box collider to block the ray into the background.
Assuming EasyTouch uses colliders, this will block the rays into the background - I don't know if they do?