4
\$\begingroup\$

Okay, so:

I am making an android game. I want everything to scale to the size of the screen I'm using. Further, my static background needs to scale (as well as every other object), but if the aspect ratio is less than the AR of the background image I want the image to be cut off at the edges.

Further, I have a game object I need to always be at the corner of the screen. I'm guessing I should use a script to determine the width of the screen and place it a few coordinates up and right of that on start?

The game is only in landscape mode if that matters. How do I go about this? I previously had the background as a plane with an image on it but it didn't take up the whole screen and I think it might not be the right thing to do? Maybe use a quad?

How do I test to make sure that this works? I only have my one android phone to test it on.

\$\endgroup\$
2
  • \$\begingroup\$ When you say scale, do you mean you want it to get bigger or smaller when the screen does itself? Will they all have the same ratio (16:9) etc? \$\endgroup\$ Commented Jan 29, 2015 at 10:38
  • \$\begingroup\$ I want everything to keep the same ratio (meaning I'm okay with the edges being cut off), and yeah I want it to get bigger or smaller with the screen. \$\endgroup\$
    – Daniel Bak
    Commented Jan 29, 2015 at 16:20

1 Answer 1

0
\$\begingroup\$

For the gameObject to always stay in the corner set it's position to camera.ScreenToWorldPoint(new Vector3(0, 0, -camera.gameobject.transform.position.z)) - new Vector3(yourObjectsizeX / 2, yourObjectsizeY / 2,0) [this to make sure the whole button is visible]

Regarding the scaling, I did a while back such a scale to the background by defining the width and it's maximum size and after scaling on Y respective to the new X. Ex. you have a background of 2048 X 1536 and background size 20.48 X 15.36. For x= 1024 you'll have y=768 hence your background will scale to 10.24 X 7.68.

Hope this helps

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .