equivalent Codea features in Pythonista
I have been using Codea for a while. I have recently downloaded Pythonista and I am trying to work with it. But since I am familiar with Codea I have two questions:
- How in Pythonista can I change Scenes? You know, I want a Scene showing first and then I want another one showing after some operations.
In Codea we have the Main routine, and you can built your main operations in its Draw(), and refer to various scenes in that.
But in all Pythonista examples there was just one Scene and I couldn't find an equivalent for Draw() of the Main routine in Lua. This is a crucial feature. Because what I want is a root routine which includes some operations and calls various Scenes.
- in Codea there are Sprites and Meshs. As iPad process meshes much faster than sprites, people use meshes. Do we have these concepts in Pythonista?
It has to be told that I don't want to compare these two great apps, I am just familiar with Codea and I want to understand its equivalent features in Pythonista
any answers for a solution for #1? I've actually built all my scenes but due to problem #1 i don't know how to relate them. help plz!
omz last edited by
There isn't really any built-in support for running multiple scenes in Pythonista. However, you could define one "master" scene that then forwards events to an "active" scene (that could be changed while the master scene is running). I've made a simple example that uses this approach here:
thank you so much. i will check that example and i guess it would be fine.
i tried to the scheme u propopsed with the "scene with layers" (Myscene) as the slave layer and a master scene (Myscene1).
unfortunately when i run Myscene1 it tells me, as the first error, that (Myscene object had no attribute "bounds"). so i guess when the slave scenes do have layers it is tricky. what do u suggest? defining all the slave scenes to work and modify just layers in the master scene?
i just realized that probably i can use another approach without multiscenes. i can built draw1(),...,drawN() and call each of them i want in draw() of a single scene. i try to see what would happen this way.
...it seems to work. so i can now use multi pages. so i guess #1 is solved for me.
eliskan175 last edited by
I was considering this problem as well and I think I have a solution.
Ok my plan with this is to have my elements of my game designed as a 'level file'. This file would contain arrays of data information on which objects of which type are spawning where. I will do this with a massive array containing a bunch of ([x,y],[width,height],typeObject) structures. Then my scene will have a 'level' variable built into it, something I can increase each time the goal is met.
So it would call like:
if self.level==1: loadLevel(self,level1,extraStuff)
elif self.level==2: loadLevel(self,level2,extraStuff)
Where essentially the loadLevel function would get all the info for objects in each level using pre-coded information. It would also modify "self" so that all the information in "self" is consistent with the new level.. Effectively making a new scene.
After you load your level, you would then perform collision tests etc and continue with the process.
idk I am still working on an idea for this because I want to design my own game on iPad and it seems as designers, we will have to create our own scenes and ways of handling them.
DBGE last edited by
While I found your solution for Multiscene very elegant, I discovered that it does not work when calling variable such as size, bounds or dt.
The reason is that these variables are apparently generate during run.
A solution is to use the following definition
def setup(self): #print 'bounds', self.bounds #print self.size self.active_scene.size = self.size self.active_scene.bounds = self.bounds self.active_scene.dt = self.dt self.active_scene.setup() def switch_scene(self, new_scene): self.active_scene = new_scene self.active_scene.size = self.size self.active_scene.bounds = self.bounds self.active_scene.dt = self.dt new_scene.setup()
with this modification the Multiscene works properly even with the nice example of multilayers with the snake.
Many thanks for all the work
ccc last edited by ccc
The rewrite of the scene module in Pythonista 2.0 adds modal scenes which make MultiScene far less needed than it was in previous versions. https://forum.omz-software.com/topic/2500/scene-transitions contains some discussion on this. Also scenes seem to me to be much more forgiving and well behaved than they were in earlier iterations of the scene module. For instance, you can now call scene.run() on multiple scene.Scenes in a single script and when you close the top scene, the next one will appear. This was not possible in the original implementation of scene. Chaining of scenes is also possible. @eliskan175 solution above probably works in Pythonista 2.0 with few mods.