Hello there!
I am programming a really simple program in panda3d (python) and I am facing some pretty strange issues.
At some point of my code, I need to change the image that’s being displayed in the background. For that purpose, I’m calling the following function:
def loadBackground(self, imagepath):
''' Load a background image behind the models '''
# We use a special trick of Panda3D: by default we have two 2D renderers: render2d and render2dp, the two being equivalent. We can then use render2d for front rendering (like modelName), and render2dp for background rendering.
self.background = OnscreenImage(parent=render2dp, image=imagepath) # Load an image object
base.cam2dp.node().getDisplayRegion(0).setSort(-20) # Force the rendering to render the background image first (so that it will be put to the bottom of the scene since other models will be necessarily drawn on top)
Which I obtained from this post
The function itself is called from this other function:
def changeWindow(self):
self.loadBackground("img/ejes/"+self.ejes[self.lap]+".jpg")
props = WindowProperties()
props.setSize(self.w[self.lap], self.h[self.lap])
self.win.requestProperties(props)
self.cam.set_y(self.distcam[self.lap])
The problem: it only works sometimes. Without changing anything in the code. Sometimes it changes the image, sometimes it doesn’t. It seems to be completely random. In the main loop, I need to change the background image 3 times. Sometimes it works well both the 3 times. Sometimes none. So strange.
Any help will be greatly appreciated. I am completely lost with this issue.
Thanks in advance!