omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Getting a game to scale on all devices

    Pythonista
    5
    5
    2637
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Behemoth
      Behemoth last edited by

      I've got a giant bunch of code for a game that I wrote specifically with numbers of pixels for just my device. I'm trying to use get_screen_size or get_screen_scale to make it work on every device but I just can't figure it out. Any help with how one can do this or anyone willing to?

      Space Lazors

      1 Reply Last reply Reply Quote 0
      • Webmaster4o
        Webmaster4o last edited by

        You're saying you wrote a game with lots of magic numbers. This is a bad habit, in the future you should write it using get_screen_size() the first time.

        It's probably not hard to change if you take an easy approach:

        1. Store values like screen_x or screen_y in your code. Try
        screen_x, screen_y = get_screen_size()
        
        1. Find all the constant numbers you have in your code.
        2. Decide whether these numbers describe height or width
        3. Express them as a proportion of the corresponding height value. For example, if you're using 400 as a height value on an iPad mini, you can express this as 0.52 * screen_y. The height on an iPad mini (in landscape) is 768. So 400 / 768.0 is 0.52. Now, if a user is on an iPad Pro in landscape, the height will be 1024. 0.52 * 1024 is 532. That value is proportional to the value you used.

        If you express all your values as a proportion to the screen size in this way, you can make a game that scales to any screen size.

        In a lot of cases, this isn't really a good approach. Scaling to different screen sizes is really not easy to do well. In many cases, it's not ideal to have the game look the same on all devices. The UI that works on an iPad is probably too small for a phone. With this approach, if you do it thoroughly, the game will look stretched in the opposite orientation (if a landscape game is played in portrait or vice versa)

        1 Reply Last reply Reply Quote 0
        • JonB
          JonB last edited by

          you could also try setting x_scale and y_scale by the appropriate ratio of whatever you have assumed in the design to the real screen size.

          1 Reply Last reply Reply Quote 1
          • ccc
            ccc last edited by ccc

            @Behemoth, you might want to consider storing all of your user configurable variables in a single .yaml file like:

            gold: 0
            highscore: 0
            shield: 0
            ship: 0
            ships: 0
            

            You could then just do:

            import yaml
            with open('laser.yaml') as in_file:
                user_settings = yaml.load_safe(in_file)
            print(user_settings)
            

            Yaml files are supersimple for users to edit.

            1 Reply Last reply Reply Quote 0
            • brumm
              brumm last edited by

              screen sizes

              import scene
              print "total screen size = " + str(scene.get_screen_size() * scene.get_screen_scale())
              

              Based on your total screen size you can work with a percental width and height. But as Webmaster40 already mentioned sometimes it's better to write different code because of the wide screen size range (iPod - iPad Pro).

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors