|
Post by alexluciani on May 9, 2011 6:14:50 GMT -5
To create the skybox I have done this method in the World class:
def create_skybox(self): myskybox = loader.loadModel("Models/skybox.egg") # Model filename myskybox.setScale(200) myskybox.reparentTo(render)
But now, to make it moves based on the camera position I tried to add this code in the update_camera function:
... self.lasttime = task.time self.myskybox.setPos(base.camera.getPos) return task.cont
and I got this error:
File "myscene.py", line 206, in update_camera self.myskybox.setPos(base.camera.getPos) AttributeError: World instance has no attribute 'myskybox'
Maybe I have done some mistake with the definition of method and how to retrieve their attributes. Did someone else solve it in different way?
Thanks
|
|
|
Post by Samuele Sabbatini on May 9, 2011 15:22:04 GMT -5
The problem is the variable myskybox! In the function create_skybox you instanciated a general variable myskybox. But in the update_camera function you use a myskybox variable as a class variable because you use self.skybox. So the solution depends on how you want use that variable, so you can add self.myskybox everywhere or remove "self." in the update_camera function. I hope that this is the solution Samuele Sabbatini
|
|
|
Post by David Sorrentino on May 10, 2011 4:15:17 GMT -5
First, try to define the variable myskybox as CLASS VARIABLE in this way:
def create_skybox(self): ···self.myskybox = loader.loadModel("Models/skybox.egg") # Model filename ···self.myskybox.setScale(200) ···self.myskybox.reparentTo(render) Then, update the position of the skybox within the method update_camera in this way:
self.myskybox.setPos(base.camera.getX(), base.camera.getY(), base.camera.getZ())
A class variable is a variable that you can access from every method of the class. You can define a class variable putting the code
self. before the variable in question.
Cheers, David
|
|
|
Post by alexluciani on May 10, 2011 4:34:47 GMT -5
Thanks to all, I have got it, in python without the prefix "self.", passed as parameter, a variable remains local to the method or class.
Cheers, Alex
|
|