I decided to try an experiment without all the hassle of getting assets together, so I’ve created a script where I’m trying to use keyboard input to change the values of buttons, sliders, labels, etc.
I still don’t have a grasp on accepting input and tasks, and I can’t decipher Roaming Ralph. Too much going on in there. XD So the question remains: how to I accept input by holding a certain key to temporarily change the state of an object?
class FlightControls(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.disableMouse()
self.createGUI()
self.a = self.accept('a-repeat', self.controls)
self.d = self.accept('d-repeat', self.controls)
self.space = self.accept('space-repeat', self.controls)
self.q = self.accept('q-repeat', self.controls)
self.e = self.accept('e-repeat', self.controls)
taskMgr.add(self.controls, "controls")
def createGUI(self):
self.leftB = DirectCheckButton(scale=0.25)
self.leftB.setPos(-0.25, 0, 0.5)
self.rightB = DirectCheckButton(scale=0.25)
self.rightB.setPos(0.5, 0, 0.5)
self.wings = DirectSlider(range=(0,100), pageSize=1, value = 50)
self.wings.setPos(0, 0, 0)
self.leftWing = DirectSlider(range = (0,100), pageSize=1, value = 50, scale = 0.5)
self.leftWing.setPos(-0.7, 0, -0.5)
self.rightWing = DirectSlider(range=(0,100), pageSize=1, value = 50, scale = 0.5)
self.rightWing.setPos(0.75, 0, -0.5)
def controls(self, task):
if self.a:
self.leftB.indicatorValue = 1
else:
self.leftB.indicatorValue = 0
ref = FlightControls()
ref.run()
P.S Does anyone know how to disable the ability to change slider values with the mouse?