How to Scale GameMaker Games on Mobile Devices - dummies

How to Scale GameMaker Games on Mobile Devices

By Michael Rohde

GameMaker: Studio allows you to scale your game for mobile devices. For mobile devices, such as tablets and phones, you’re configuring the full display size instead of a window. Because of this, you only have to deal with a single aspect ratio, unless you allow for landscape and portrait settings from the Global Game Settings window.

  1. From the Resource tree, in the Objects folder, double-click obj_Control (if it’s not open from earlier).

    The Object Properties appear.

  2. Click the Step Event from the Events section.

    The Actions for the Step Event appear in the Actions section.

  3. Double-click the Execute Code Action from the Actions section.

    The code window appears.

  4. In the code window, type the following (the code in bold indicates the original code):

    switch(os_type)
    {
    case os_macosx:
    case os_windows:
    case os_linux:
    case os_win8native:
    if cur_width != window_get_width() || cur_height != window_get_height()
            {
            scr_Resize();
            }
        break;
    case os_ios:
    case os_android:
    case os_winphone:
    case os_tizen:
        if cur_width != display_get_width() || cur_height != display_get_height()
            {
            scr_Resize();
            }
        break;
    }

    This code checks the operating system of the device running the game.

  5. Click the green check mark to save and close the code window.

Now you need to update the Script. Here is how to do the next part.

  1. From the Resource tree, in the Scripts folder, double-click scr_Resize.

    The Script code window appears.

  2. Replace the first two lines of code with the following:

    switch(os_type)
    {
    case os_macosx:
    case os_windows:
    case os_linux:
    case os_win8native:
        cur_width = max(1, display_get_width());
        cur_height = max(1, display_get_height());
        break;
    case os_ios:
    case os_android:
    case os_winphone:
    case os_tizen:
        cur_width = max(1, display_get_width());
        cur_height = max(1, window_get_height());
        break;
    }
  3. Click the green check mark to save and close the code window.

Now when you run the game on any mobile device, you should see that the game scales correctly no matter the resolution of the device or if you change the orientation from landscape to portrait. You should also notice that more of the Room is displayed in landscape mode rather than portrait.