Hello Guest

Author Topic: positioning a mouse cursor  (Read 3517 times)

David Kalina

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
positioning a mouse cursor
« on: October 28, 2013, 10:49:35 pm »
I'm trying to position my own mouse cursor on the screen.  For some reason, the results are not what I expect when the preview resolution != native resolution.

I am using a tk2dUICamera with a native resolution of 960X640, orthographic projection, 1 pixel per 'meter'.  The Unity preview resolution is 1280x800.

In the example image (attached), you can see how I can manually set the position of the sprite to x=0 and it is drawn well inside the camera's left boundary.  I would expect that an object positioned exactly at x=0 would be exactly on the left border of the camera.

The assumption I've been operating under is that I can position things "on screen" by setting their world position to a screen pixel resolution.  Not sure where I'm going wrong.  I am guessing that I am failing to understand something about how native resolution works.  When preview == native, everything is exactly where I expect it to be.

Thanks in advance!
David

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: positioning a mouse cursor
« Reply #1 on: October 29, 2013, 10:11:36 am »
When preview resolution != native resolution, the camera rescales to show more or less information - this is configured using the overrides. If you're using fit visible, it will compress the native resolution image to display inside the preview resolution. I.e. in your image its displaying more data horizontally, which inevitably means that there is data beyond x < 0. This allows you to not have to reposition everything in your game depending on resolution, but simply design for one resolution and display more or less on others.

If you want to get exact positions on screen, you can either use tk2dCamera.ScreenExtents to get the extents after scaling, or use camera.ScreenToWorldPoint to get a world position for a point on screen.