playMaker

Author Topic: Is there a way to make everything relative to screen size?  (Read 3681 times)

ptrlo

  • Playmaker Newbie
  • *
  • Posts: 31
Is there a way to make everything relative to screen size?
« on: October 09, 2014, 02:33:53 AM »
If I make a mobile game that would be full screen on any iOS or Android device, and say I have falling blocks from the top, how would I got about making sure they spawn across the whole axis, no matter what device?

How do Unity coordinates relate to device coordinates?

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: Is there a way to make everything relative to screen size?
« Reply #1 on: October 09, 2014, 11:41:32 AM »
It depends on if you're talking about 2D or 3D gameplay.

ptrlo

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Is there a way to make everything relative to screen size?
« Reply #2 on: October 09, 2014, 05:04:06 PM »
It's a top down space game. How do I even approach this?

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: Is there a way to make everything relative to screen size?
« Reply #3 on: October 09, 2014, 07:01:24 PM »
Again, it depends if you're using 3D or 2D space.

ptrlo

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Is there a way to make everything relative to screen size?
« Reply #4 on: October 09, 2014, 07:46:00 PM »
I have a top down camera looking down along the Y-axes and the projection is orthographic. I am using a combination of sprites and 3D objects.

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: Is there a way to make everything relative to screen size?
« Reply #5 on: October 09, 2014, 08:10:25 PM »
As you're doing it in 3D space, then you'll have to adjust your camera settings based on the device/resolution the user is running.

For example an iPhone5 resolution is a widescreen style display, as apposed to an iPad1 which is a 4:3 1024x768, so you'll miss the 3D space that's on either side of the screen.

I would suggest you do a windows standalone build, and use the "Screen Set Resolution" action to switch between the range of resolutions you want to support. Add them to a key press so you can quickly cycle between them, and you'll be able to easily see how Unity cameras handle each one.

I guess you'll probably end up needing to modify the camera FOV and/or position  slightly based on device/resolution to make it look right.

ptrlo

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Is there a way to make everything relative to screen size?
« Reply #6 on: October 09, 2014, 09:25:13 PM »
Thanks for the reply. How do I make this work for all Android devices? I am fine with the playfield being whatever ratio the android device is, but if I am spawning things at the top border, I also need to know where it is on each device.

How do I relate the camera position to Unity coordinates and device resolution?

I would like to have GUI elements in the middle, another in a left corner (The game is portrait) but also gameplay elements.. For example, the player starting at 25% of the distance from bottom to top.

ptrlo

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Is there a way to make everything relative to screen size?
« Reply #7 on: October 09, 2014, 09:26:14 PM »
I've also been trying to have clamp work on horizontal (x axis) movement, but it doesn't work. And this too would have to be relative to the device.

jess84

  • Hero Member
  • *****
  • Posts: 515
Re: Is there a way to make everything relative to screen size?
« Reply #8 on: October 09, 2014, 09:46:24 PM »
GUI elements aren't a problem, as they're set to positions based on the screen - rather than the gameworld.

For Android, you really can't cater for all possible resolutions.

This is the current state of the market for fragmentation;
http://opensignal.com/reports/2014/android-fragmentation/

And Google Play lists 6,400+ devices at the moment.

I'd suggest looking at the most popular devices' resolutions, and look at some of the extreme resolutions, and test that your game looks ok with those. There'll always be some weird device that has an odd resolution.

ptrlo

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Is there a way to make everything relative to screen size?
« Reply #9 on: October 09, 2014, 10:04:28 PM »
But if I can detect screen resolution and figure out a formula for the camera and gameplay elements, I could make it work for all devices in theory, right?