Hello Guest

Author Topic: Help on movement issue with different resolution  (Read 4955 times)

blueskined

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Help on movement issue with different resolution
« on: February 10, 2013, 07:05:41 am »
Hi while I am exploring the tk2dcamera, I met a problem that can't get across of.
I am working with a native resolution: 960 x 640, and a cube moving across the screen(left -> right ->left) yoyoly.
the position all based on the screen size dynamically, and a override resolution of wildcard.

it's working without any issue under 960 x 640, but when I change the resolution, and hit play, the cube is moving towards outside of the screen view! I tried 1024 x 768, or Iphone5, non of them seems working correctly.

I printed out the screen size, seems the size is captured correctly, can someone tell me how to solve this? I want the cube moving correctly under any resolution.
for the sake of clearness, I attached a demo project for you to exam. looking forward your feedback.

thank you very much.
(unity4.0 project and I can't use camera anchor in the current project, however, I tried the anchor anyway, and it's still not working... :o)
(btw, if you change the resolution while the game is playing, it seems working but the cube been squashed, if you stop playing, change the resolution, hit play again, it's not working, in reality when player install app in different devices, it should be the same as hit a fresh play right??)
« Last Edit: February 10, 2013, 01:14:42 pm by unikron »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help on movement issue with different resolution
« Reply #1 on: February 10, 2013, 01:38:05 pm »
Ah. I see what you're trying to do.
So, what you want is for it to fit the resolution, AND reach the edges when the aspect ratio doesn't match?

You should use tk2dCamera.inst.ScreenExtents like so:
Code: [Select]
Rect rect = tk2dCamera.inst.ScreenExtents;
float y_top = rect.yMin;
float y_bot = rect.yMax;
float x_lhs = rect.xMin;
float x_rhs = rect.xMax;

moveToPostion = new Vector3(x_rhs - 20, Screen.height/2, testSprite.transform.position.z);
startPosition = new Vector3(x_lhs + 20, Screen.height/2, testSprite.transform.position.z);

Changing res while the game is playing isn't going to be great, but it'll work fine on device.
Also, in your set up, you should delete the override and add a new one (-1 width, -1 height). Its not worth adding resolution specific widths unless you really need them for something specific.


blueskined

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Help on movement issue with different resolution
« Reply #2 on: February 10, 2013, 02:13:26 pm »
Hello There:
It's magically working now!
Thanks a lot.
Chreez!

blueskined

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Help on movement issue with different resolution
« Reply #3 on: February 10, 2013, 03:00:40 pm »
Hi again:
Most of the things are working, but there is still a bit issue with the height, here is what I got.


here you see: the sprite square is located at 0, 0, 0, where the down left corner, at 960*640 resolution.


but when I change to 1024*768, the 0,0,0 position is apparently offseted.


when I hit play, obviously the offset is remain, although I am trying to put the height to center of the screen, is actually the center + the offset value!
(I am using y_bot+y_top/2 to get the center height. Screen.Height/2 couldn't get right height either...)

please check it, thanks a lot.
BS.
« Last Edit: February 10, 2013, 03:05:14 pm by blueskined »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help on movement issue with different resolution
« Reply #4 on: February 10, 2013, 03:31:12 pm »
That is correct. x_lhs, x_rhs, etc. are coordinates, not offsets, so the correct value of the center y,
is y_bot + (y_top - y_bot) * 0.5f;
= (y_bot + y_top) * 0.5f;
This picture should explain what is going on, and hopefully it makes sense why it is doing that.

If you don't need it to do this, then you can turn off the overrides, but that will of course mean you are responsible in scaling everything, making everything fit for different resolutions.

blueskined

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Help on movement issue with different resolution
« Reply #5 on: February 10, 2013, 05:32:35 pm »
Ha, it's eventually running perfectly.
Thank you very much. ;D
BS~~~