def frame(self, ev): nt = getTimer() delta = (nt - self.lastframe)*0.001 for fun in values(self.handlers): fun(delta) self.lastframe = nt if self.show_fps: self.fps.text = 'fps: ' + (1/delta).toFixed(2)
def start(self, sprite, show_fps=False): self.sprite = sprite self.lastframe = getTimer() self.handlers = [] sprite.addEventListener(Event.ENTER_FRAME, self.frame) self.show_fps = show_fps if show_fps: self.fps = TextField() sprite.addChild(self.fps)