Hello Guest

Author Topic: Tk2dCamera, Tk2dTextMeshes, and perfect pixel placement.  (Read 4429 times)

vancext

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Tk2dCamera, Tk2dTextMeshes, and perfect pixel placement.
« on: September 29, 2014, 04:04:11 am »
Heya, this may be an easy fix, but I'm having a hard time with it.

I am currently using tk2dtextmeshes with a tk2dcamera, and I am trying to position them at runtime on exact pixels so the text looks perfect.

For instance:

textMesh.transform.position = new Vector3(Mathf.RoundToInt(Screen.width - (20f * resolutionAdjust)), . . . );

This X value is a whole number at runtime (if screen.width is 480, this debug.logs as 468 given my resolution adjust). However, after it gets repositioned automatically to the tk2dcamera (which translates everything to a 0,0 center on the screen) the new X in the editor is 291.84. I'd love to round the new value to the nearest integer for crisp text, but I can't figure out how.

Any advice?

Thanks for your time. :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tk2dCamera, Tk2dTextMeshes, and perfect pixel placement.
« Reply #1 on: September 29, 2014, 11:09:34 am »
How is your tk2dCamera set up?

vancext

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Tk2dCamera, Tk2dTextMeshes, and perfect pixel placement.
« Reply #2 on: September 30, 2014, 01:42:14 am »
Inherit Config: None
Native Res: 600 x 1024
Preview Res: 480 x 800
Projection: Ortho
Type: Pixels Per Meter
PPM: 1
Origin: Bottom Left
Zoom Factor: 1

Overrides: Wildcard Override w/ default settings (is this the issue?)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tk2dCamera, Tk2dTextMeshes, and perfect pixel placement.
« Reply #3 on: September 30, 2014, 10:36:29 am »
The default override is set to Fit Visible. That will take your 600x1024 image and rescale that to fit in 480x800.

If you're setting up your game to be pixel perfect on 600x1024, all you need to do is make the position rounded to the closest unit (i.e. no decimal places). If you're rescaling you need to find some common factor - in most cases you don't have to reposition anything as long as you take scaling into consideration.

Otherwise, you'll need to figure out the world size of one pixel and snap to that. You can do that by -
Code: [Select]
Vector3 worldPixelUnit = tk2dCamera.camera.ScreenToWorldPoint(new Vector3(1,1,0)) - tk2dCamera.camera.ScreenToWorldPoint(new Vector3(0,0,0));
Now all you need to do is snap to this value.


vancext

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Tk2dCamera, Tk2dTextMeshes, and perfect pixel placement.
« Reply #4 on: September 30, 2014, 04:33:51 pm »
So good -- thank you for your help. I'll give it a go tonight!