Changing Scene

yoshi

28-06-2006 13:23:02

Hi,
I'm a pyogre beginner and I was wondering how to change scene in my game. I've created two scenes, one with a dragon in the middle of space, and the other with a dragon with a 90 degrees yaw rotation:


from pyogre import ogre
import SampleFramework

class Scene1(SampleFramework.Application):
def _createScene(self):
ent = self.sceneManager.createEntity("Dragon1","dragon.mesh")
node = self.sceneManager.rootSceneNode.createChildSceneNode("Dragon1 Node")
node.attachObject(ent)

class Scene2(SampleFramework.Application):
def _createScene(self):
ent = self.sceneManager.createEntity("Dragon2","dragon.mesh")
node = self.sceneManager.rootSceneNode.createChildSceneNode("Dragon2 Node")
node.attachObject(ent)
node.yaw(ogre.Degree(90))

if __name__ == "__main__":
Scene1 = Scene1()
Scene1.go()


This code opens the first Scene correctly. Now I want to change the scene to Scene2 (For example when the user presses 'C' key), but I don't know how to do..

Thanks in advance :wink:

willism

28-06-2006 14:51:01

I don't think your current code will work. You are creating two subclasses of SampleFramework.Application. The problem with this is that you are making two full-blown PyOgre application classes in one python file, each including the ogre initialization and shutdown stuff (among other things).

There are several ways to "change scenes" like you want to. One simple way would be to write a class like so:


...
class Scene(SampleFramework.Application):
def _createScene(self):
ent = self.sceneManager.createEntity("Dragon1","dragon.mesh")
node = self.sceneManager.rootSceneNode.createChildSceneNode("Dragon1 Node")
node.attachObject(ent)

def _changeScene(self):
self.sceneManager.destroyAllEntities()
ent = self.sceneManager.createEntity("Dragon2","dragon.mesh")
node = self.sceneManager.rootSceneNode.createChildSceneNode("Dragon2 Node")
node.attachObject(ent)
node.yaw(ogre.Degree(90))
...


Then write an input listener that calls the _changeScene method. Refer to SampleFramework.py (and the API docs) for more info on how to get user input. Note that this way of doing it is an awful hack; Eventually you will want to replace SampleFramework with your own framework that has better support for changing scenes.

yoshi

28-06-2006 20:38:28

Thank you, I'll try it out :wink: