I have problem.
At TitleScreen class, I am creating a cursor which change position when up or down arrow button is pressed. Now, when I pressed the button, the cursor doesn’t move.
The button input itself works fine when I tested it with sys.exit.
So, I suspect that the problem is at the draw mechanism, but I am not so sure. Plus, I don’t know how to solve it.
Here is the code I use
from direct.gui.OnscreenImage import OnscreenImage
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from math import pi, sin, cos
from panda3d.core import TextNode
from pandac.PandaModules import WindowProperties
from pandac.PandaModules import TransparencyAttrib
from panda3d.core import loadPrcFileData
import sys
import direct.directbase.DirectStart
from pandac.PandaModules import *
#######################################
def drawText(x,y,text):
return OnscreenText(text=str(text), style=1, fg=(1,1,1,1),
pos=(x,y), align=TextNode.ARight, scale = .07)
#######################################
class MenuAbstract(ShowBase):
def __init__(self,cursorIndex,indexSize):
self.titleText = [""]
self.cursorIndex_ = cursorIndex
self.indexSize_ = indexSize
def ceilLimit(self):
if self.cursorIndex_ == 0 :
self.cursorIndex_ = self.indexSize_ - 1
else:
self.cursorIndex_ -= 1
def floorLimit(self):
if self.cursorIndex_ == self.indexSize_ -1 :
self.cursorIndex_ = 0
else:
self.cursorIndex_ = 1
def controlTitle(self):
self.accept('arrow_up', self.ceilLimit)
self.accept('arrow_down', self.floorLimit)
###########################################
class TitleScreen(MenuAbstract):
def __init__(self):
MenuAbstract.__init__(self,0,2)
self.titleText_ = ["Begin","Continue"]
def drawTitle(self):
drawText(-0.5,0.5,self.titleText_[0])
drawText(-0.5,0.4,self.titleText_[1])
drawText(-0.8,0.5-(self.cursorIndex_*0.1),">")
drawText(-0.8,0.2,self.cursorIndex_)
drawText(-0.8,0.1,self.indexSize_)
drawText(-0.8,0.3,self.titleText_[self.cursorIndex_])
###########################################
class Game(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.accept('escape', sys.exit)
## Room: Title
title = TitleScreen()
title.drawTitle()
title.controlTitle()
title.drawTitle()
app = Game()
app.run()
Sorry for my bad grammar.
Thanks!