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.
Control Ui in Scene?
DoinStuffMobile last edited by
I was wondering if it is possible to put a joystick-like control on a game in scene (think like on a mobile rpg game)?
I have tried different combinations of touch_began and moved but the three things i am looking for are:
Character moves in direction the touch is dragged from initial touch, but not to the location of touch
For this to only happen on one side of the screen (example : only on the left side)
Is possible to have an overlay that includes a joystick on the left and buttons on the right, for example. I can provide pictures if i haven't described this well enough.
Thank you for any guidance or links to where to look. I've only looked at the Scene and Turtle documentation and tinkered around.
If this is not possible I also was wondering if Pythonista's Turtle module would be getting keyboard inputs back since the popularity of bluetooth, smart, and magic keyboards? I think it currently doesnt include them, right? 😅
Thanks again! I haven't ever made a thread before, but I've learned a lot from reading others.
mikael last edited by
@DoinStuffMobile, all of your goals are feasible and nothing too exotic.
The trick to handling touches on different sides of the screen in Scene is to use
touch_idproperty of a touch to differentiate between them, and of course the location to see which side of the screen the touch starts in.
Connecting external keyboard keypresses to turtle logic seems easy as well, but I have done nothing with physical keyboards and Pythonista.
mikael last edited by
@DoinStuffMobile, here’s a very simple example of touches on different sides of the screen controlling different things:
from scene import * import math class MyScene (Scene): def setup(self): l = self.left_ship = SpriteNode('spc:PlayerShip1Orange') l.position = (self.size.width / 4, self.size.height / 2) l.rotation = -math.pi / 2 self.add_child(l) r = self.right_ship = SpriteNode('spc:PlayerShip3Blue') r.position = (self.size.width / 4*3, self.size.height / 2) r.rotation = math.pi / 2 self.add_child(r) self.left_touch = self.right_touch = None def touch_began(self, t): on_left = t.location.x < self.size.width / 2 if on_left and self.left_touch is None: self.left_touch = t.touch_id elif not on_left and self.right_touch is None: self.right_touch = t.touch_id def touch_moved(self, t): touch = t.touch_id if not touch in (self.left_touch, self.right_touch): return delta_y = t.location.y - t.prev_location.y if touch == self.left_touch: ship = self.left_ship elif touch == self.right_touch: ship = self.right_ship x, y = ship.position ship.position = x, y + delta_y def touch_ended(self, t): touch = t.touch_id if touch == self.left_touch: self.left_touch = None elif touch == self.right_touch: self.right_touch = None run(MyScene())