Hello all, i currently have a task that i need to run once the mouse is clicked. Sadly the only way i know to control when a task is executed is do later tasks, and they only use time to tell them when to start.
from direct.showbase.ShowBase import ShowBase
from direct.showbase import DirectObject
from direct.task import Task
from direct.gui.OnscreenText import OnscreenText
from math import pi, sin, cos
hitcount = 0
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
base.disableMouse()
self.box = self.loader.loadModel('samples/Ball-in-Maze/models/ball')
self.box.reparentTo(self.render)
self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
def spinCameraTask(self, task):
angleDegrees = task.time * 100
angleRadians = angleDegrees * (pi / 180.0)
self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
self.camera.setHpr(angleDegrees, 0, 0)
return Task.cont
class Hello(DirectObject.DirectObject):
def __init__(self):
self.accept('mouse1',self.hitcountfunction)
self.accept('mouse3',self.hitcountfunction)
self.accept('z',self.hitcountfunction)
self.accept('x',self.hitcountfunction)
def hitcountfunction(self):
global hitcount
hitcount += 1
print hitcount
def cpm( self, task ):
if task.time < 20:
task.time and \
cpm.setText(
str(
round(
(hitcount / ( task.time / 60 )) / 4,
2 ) ) )
return task.cont
h = Hello()
app = MyApp()
cpm = OnscreenText( pos = ( 0, -.2 ), scale = .05, mayChange = True )
app.taskMgr.add( h.cpm, '...' )
app.run()
i need the
app.taskMgr.add( h.cpm, '...' )
task to only be executed once
self.accept('mouse1',self.hitcountfunction)
self.accept('mouse3',self.hitcountfunction)
self.accept('z',self.hitcountfunction)
self.accept('x',self.hitcountfunction
one of those happens. is that possible?