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.


    Determine if script is run on iPhone or iPad? (SOLVED)

    Pythonista
    3
    4
    2651
    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.
    • Sebastian
      Sebastian last edited by

      Is there any way to determine if a script is run on an iPhone or an iPad?
      I'm creating a game and I want it to be able to run both on an iPhone and an iPad.
      Like for instance:
      <PRE>
      class Alien(object):
      def init(self):
      self.width = 60 if run_on_ipad else 30
      </PRE>

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

        Why not base the size of your alien on the x/y dimensions of the screen, which you can get from the Scene module, instead of a specific device model?

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

          You could use the <code>size</code> property of your scene. Have a look at the bundled "Clock" script for an example. It uses different margins, line widths, etc. depening on the type of device (iPad/iPhone).

          The bundled "Cascade" game uses a similar approach to determine the number of tiles that fit on the screen.

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

            Thanks guys! I used the same approach as the one used in the "Cascade" game.

            <PRE>
            from scene import *

            class Alien(object):
            def init(self):
            ipad = WIDTH > 700
            self.width_and_height = (60,60) if ipad else (30,30)

            def draw(self):
                image('Alien_Monster',100,100,*self.width_and_height)
            

            class MyScene(Scene):
            def setup(self):
            global WIDTH; WIDTH = self.size.w
            self.alien = Alien()

            def draw(self):
                self.alien.draw()
            

            run(MyScene(), PORTRAIT)
            </PRE>

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