Jump to content


Photo

Screen Resolution on Android


  • Please log in to reply
6 replies to this topic

#1 The Legend

The Legend

    Unashamed

  • GMC Member
  • 1128 posts
  • Version:GM:Studio

Posted 20 November 2012 - 12:32 AM

How do I go about having a perfect screen resolution for all android phones that doesn't stretch my sprites?
  • 0

#2 Cheppa

Cheppa

    GMC Member

  • GMC Member
  • 50 posts

Posted 20 November 2012 - 12:38 AM

I've been wondering this same thing a while now... I think the best/easiest/only(?) approach is to use views. Get the device screen width and height and then resize your views accordingly.

Edited by Cheppa, 20 November 2012 - 12:41 AM.

  • 0

#3 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3536 posts
  • Version:GM:Studio

Posted 20 November 2012 - 12:56 AM

Depends on how you want it.. do you want to scale th view size, do you want to stretch the screen size but keep it 1:1? do you want to stretch the whole thing without worryng if it stretches?
  • 0

#4 ultrav33

ultrav33

    GMC Member

  • GMC Member
  • 315 posts
  • Version:GM:Studio

Posted 22 November 2012 - 08:20 PM

I am looking for the same answer. I want it to scale to the screen size
  • 0

#5 ultrav33

ultrav33

    GMC Member

  • GMC Member
  • 315 posts
  • Version:GM:Studio

Posted 22 November 2012 - 08:21 PM

but i still want the sprites to not be stretched. like a 32x32 to stay as a 40x40 or 50x50 or so on.

*SORRY FOR DOUBLE POST

Edited by ultrav33, 22 November 2012 - 08:22 PM.

  • 0

#6 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3536 posts
  • Version:GM:Studio

Posted 22 November 2012 - 09:04 PM

Okay, look, assume you have a game that requires to be played on a view size of 768px height, but you dont want it to get stretchd. You will notice all screens are completely different in terms of aspect ratio and sizes, but you only need to modify the view width, because that is what is causing the stretching; different aspect ratios.
In this case, you only modify the view width based on the aspect ratio, and leave the view height as-is. This will give you a perfect scaling on all screens.. a more practical example:

You have your room set by default to 1280x768 (both view width and ports!)
You have your device screen at 854x480 (portrait mid-depth standard on android)

You will notice the game gets stretched on the X axis, because the width of your game is too large, you need to:
calculate screen aspect ratio: 854/480 = 1.779
calculate the new width you should have to match that aspect ratio, based on the height: 768*1.779 = 1363.968
Apply changes, and thats it!

This is the code:
// get the display size so we dont have to call the functions all the time
globalvar display_w, display_h;
display_w = display_get_width();
display_h = display_get_height();

if os_type == os_android || os_type == os_ios {
    // Calculate aspect ratio
    aspect_ratio = display_h/display_w;
    if (display_w > display_h) {
        aspect_ratio = display_w/display_h;
    }
    // Set the view width proportional to the aspect ratio
    // Notice the height stays the same!
    view_wview = 768*aspect_ratio;
    // Also the port, to avoid stretching
    view_wport = view_wview;
}

This may stretch down the sprites, or upwards, but it will always be 1:1 ;)

Edit: this can also be used to do the opposite: sctretch height instead of width, but the most coomon case is the firt.

Edited by Manuel777, 22 November 2012 - 09:07 PM.

  • 3

#7 The Legend

The Legend

    Unashamed

  • GMC Member
  • 1128 posts
  • Version:GM:Studio

Posted 22 November 2012 - 09:07 PM

Brilliant! Thanks mate!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users