Forum Archive

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

Sebastian

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:

class Alien(object):
    def __init__(self):
        self.width = 60 if run_on_ipad else 30
tahoma5

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?

omz

You could use the size 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.

Sebastian

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

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)