Here’s my code and what I’m seeing:
class MyGame(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.GAME_FONT = loader.loadFont(GAME_STORY + "/art/gui/" + "gnatfont.ttf")
self.screenTitle()
def screenTitle(self):
logFile("show title screen")
self.scrTitle = DirectFrame(image=GAME_STORY + "/art/gui/game_title.jpg", frameSize=(-1.33,1.33,-1.0,1.0), image_scale=(1.34, 0, 1))
self.cmdChar = self.myGUIButton("Battle!", self.playBattle, (-.6,0,-.9), self.scrTitle)
self.cmdChar = self.myGUIButton("Options", self.screenOptions, (-.2,0,-.9), self.scrTitle)
self.cmdChar = self.myGUIButton("Credits", self.screenCredits, (.2,0,-.9), self.scrTitle)
self.cmdChar = self.myGUIButton("Quit Game", self.quitGame, (.6,0,-.9), self.scrTitle)
def screenOptions(self):
self.scrOptions = DirectFrame(image=GAME_STORY + "/art/gui/game_options.jpg", frameSize=(-1.33,1.33,-1.0,1.0), image_scale=(1.34, 0, 1))
self.cmdMenu = self.myGUIButton("Main Menu", self.screenTitle, (-1,0,-.9), self.scrOptions)
def screenCredits(self):
self.scrCredits = DirectFrame(image=GAME_STORY + "/art/gui/game_credits.jpg", frameSize=(-1.33,1.33,-1.0,1.0), image_scale=(1.34, 0, 1))
self.cmdMenu = self.myGUIButton("Main Menu", self.screenTitle, (-1,0,-.9), self.scrCredits)
def myGUIButton(self, text, command, pos, parent):
return DirectButton(text=text, command=command, pos=pos, parent=parent,
frameSize=(-.2,.2,-.07,.07), relief=DGG.RAISED, borderWidth = (0.03, 0.03), text_font=self.GAME_FONT,
text_scale=.04, text0_fg=(0,0,1,1), text1_fg=(1,0,0,1), text2_fg=(1,1,0,1), text3_fg=(0,1,1,1))
def playBattle(self):
self.scrTitle.destroy()
self.gameControls()
base.disableMouse()
base.camera.setPos((133, -132, 67))
self.mouseX = 0
self.mouseY = 0
self.mouseDrag = False
self.camTarget = Vec3()
self.camDist = 200
self.camTrack = False
etc... rest of 3d game code
when the game starts up the fram, scrTitle is shown. If I click the “Battle” button to play, it goes to playBattle and everything works fine.
If I click any other button 1st (say “Credits”) and then use the “Main Menu” button on Credits to go back to scrTitle and then launch the game with “Battle” - the title screen never goes away . I can tell the gaem code has started because some ot the game ui pops up on top of the title jpg, but I can’t see the 3d scene.
I tried adding a scrOptions.destroy(), but then I need to know if it exists. I added a flag to set if the user ever clicks the Options button and then check it to see if I should destroy. Still the same result.