Hello Guest

Author Topic: How to set pixel-perfect scale for Tilemaps in perspective cameras  (Read 6484 times)

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Hi, continuing on here from the Unity forums as requested:

Quote
There isn't an equivalent of the 1:1 function, but it really is quite easy to work out what the scale should be. Post on the support forum (www.unikronsoftware.com/2dtoolkit/forum) and I'll be happy to help - it'll likely just get lost in this thread. You can work out exactly what the scale should be to be pixel perfect at a set distance.

So if you could assist and inform me how to go about setting a tilemap to be pixel perfect in perspective that would be great, thanks. :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to set pixel-perfect scale for Tilemaps in perspective cameras
« Reply #1 on: June 20, 2013, 04:39:02 pm »
Assuming you're not changing the resolution from the res the sprite collection was built for - you can work out the scale to be pixel perfect - it is a function of camera fov & z distance to camera.

Code: [Select]
tk2dPixelPerfectHelper.CalculateScaleForPerspectiveCamera( fov, zdist ) / Collection.invOrthoSize
will give you the appropriate scale that needs to be applied to the sprite to make it pixel perfect at that distance.

FYI - the code from tk2dBaseSprite.MakePixelPerfect can be transferred directly to your tilemap to get it to scale appropriately. You will need to customise the tilemap code slightly to apply it automatically, though.

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: How to set pixel-perfect scale for Tilemaps in perspective cameras
« Reply #2 on: June 20, 2013, 11:45:38 pm »
Thanks for that, I bought the software and have had a bit of a play now. I do have some follow up questions:

1. In the sprite collection I set target height and ortho size - what should the ortho size be if I am not using ortho camera? 1? Irrelevant?
2. Where/how do I actually set the scale value for tilemaps?
3. In the tutorial interface pictures under Tile Properties there is a 'Layer Offset' parameter that doesn't seem to exist in the version I have. Is that coming back, or is there a workaround for setting layer separation?

Thanks again, looks to be a quality product.

edit: Regarding #3, I see the tileMapData asset has a "Z" parameter for each layer, but changing it doesn't seem to do anything.
« Last Edit: June 21, 2013, 02:39:52 am by profanicus »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to set pixel-perfect scale for Tilemaps in perspective cameras
« Reply #3 on: June 21, 2013, 11:25:58 am »
1. Mostly irrelevant, as you will be scaling it manually. Target height is relevant - it is the main resolution you're targetting. Don't worry about scaling for other resolutions just yet.

2. You would set it on the tilemap object itself. The problem is you can't set the scale per layer at the moment, but that can be fixed by manually setting it on the layer object. Try it out and see if that will work for you - you'll lose the setting each time you commit - this scale should be applied to each layer when the game starts, otherwise it'll be hard if not impossible to paint.

3. Layer offset is that box to the left of the layer selection dropdown. Set it to a positive number to offset that number by that many units per frame. When you add a new layer it sets the layer separation to 0.1 (i.e. it will be 0.1 units in front of the previous layer).

p.s. I've added you to the prerelease group, the new beta tilemap editor is way way better than the one in 2.0 right now, probably worth jumping into that if you fancy testing it out.

profanicus

  • 2D Toolkit
  • Full Member
  • *
  • Posts: 167
    • View Profile
Re: How to set pixel-perfect scale for Tilemaps in perspective cameras
« Reply #4 on: June 21, 2013, 12:30:26 pm »
Excellent, thanks again. All good now.

My problem with the layers came down to it working backwards to how I expected. I was trying to shift background layers along +Z away from the camera by typing in positive numbers. But it actually works by shifting foreground layers along -Z towards the camera by typing in positive numbers. Now I know.

I grabbed the beta from the pre-release forum and will take it for a spin, cheers.