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)
-
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> -
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?
-
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.
-
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>