I am learning Python through Pythonista on the iPhone. The first thing I did was make a simple touch-screen joystick (controller). Im starting to work on the actual game, but i don't know how to merge or overlay the 2 scenes. (One is the actual game, the other is the controller I made in another file.) I have already tried importing and running it, but it seems like only 1 could be run at once, the controller file or the game file. Any help is appreciated.
-
I don't think there is any way to overlay scenes. Even if you could, it would mean having multiple event loops running simultaneously and getting in each other's way. You will need to implement the other game objects, alongside the controller, in the same scene. – Simon Hibbs May 12 '17 at 12:25
-
@SimonHibbs So then how would I go about making a complex game? It seems so messy to just slop on what I need to a touch_moved() function every time. – BrrrIce May 12 '17 at 23:49
2 Answers
I'll try to present a more complete response than my comment above.
Each scene that is being presented has a view and a set of methods for responding to touch events in that view. You can't layer scenes on top of each other and have both respond to touch events because then you'd have two different touch event handlers triggering for the same touch events.
However you should be able to create multiple scenes that do not have overlapping views. Then each touch event will only be captured by the scene that owns the region of the screen you are touching.
You can overly a scene on top of another, but the 'overlay' scene will capture all touch interactions.

- 5,941
- 5
- 26
- 32
-
Thanks for the help. However, i found it more useful to just import another .py file that i made with the joystick in it, then insert it as a module in the main game, then just use the functions of it. It takes it down to 1 line in my main game, which is better. – BrrrIce May 16 '17 at 12:08
Instead of putting the joystick on a separate scene, you should draw it on a scene.Node
. Then in your game scene, you can add it like another sprite, using Scene.add_child()
.
To convert the touch positions to the nodes coordinate system, you can use Node.point_from_scene()
, and to convert back to the scene’s coordinate system, you use Node.point_to_scene()

- 556
- 5
- 11