本文整理汇总了Python中Input._update方法的典型用法代码示例。如果您正苦于以下问题:Python Input._update方法的具体用法?Python Input._update怎么用?Python Input._update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Input
的用法示例。
在下文中一共展示了Input._update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Color
# 需要导入模块: import Input [as 别名]
# 或者: from Input import _update [as 别名]
#.........这里部分代码省略.........
if startGame:
self.startGame()
def startGame(self):
if self._debugMode:
print("Initializing game...")
self._running = True
self._mainWindow = tk.Tk()
self._mainWindow.protocol("WM_DELETE_WINDOW", self.stopGame)
self._mainWindow.title(self._title)
self._mainWindow.resizable(0, 0)
self._renderer = Renderer(self)
self._gameInput = Input(self)
try:
self._mainCanvas = tk.Canvas(
self._mainWindow, width=self._size[0], height=self._size[1],
borderwidth=0
)
self._mainCanvas.pack()
self._mainCanvas.update()
except:
self._mainWindow = None
if self._debugMode:
print("!!! Unexpected error occurred on startGame.")
raise
if self._debugMode:
print("Game running...")
lastTimer = self.getTimeMicros()
lastTime = lastTimer
renderDelta = 0
updateDelta = 0
frames = 0
updates = 0
microPerRender = 1000000 / self._targetFPS
microPerUpdate = 1000000 / self._targetUPS
while self._running:
timeNow = self.getTimeMicros()
timeDelta = (timeNow-lastTime)
renderDelta += timeDelta
updateDelta += timeDelta
lastTime = timeNow
if updateDelta > microPerUpdate:
updateDelta -= microPerUpdate
updates += 1
if self._currentScene is not None:
self._gameScenes[self._currentScene].onUpdate(
self._gameInput, timeDelta/1000000.0
)
self._gameInput._update()
if not self._vSync or renderDelta > microPerRender:
renderDelta -= microPerRender
frames += 1
if self._currentScene is not None:
self._renderer.clearAll(self._gameBG)
self._gameScenes[self._currentScene].onRender(
self._renderer, renderDelta
)
if self._showFPS:
self._renderer.setColor(Color(255, 255, 255))
self._renderer.drawString(
(10, 5), self._infoText, tk.NW, tk.LEFT
)
self.sleep(self._idleTime)
if self.getTimeMicros() - lastTimer >= 1000000:
self._PSInfo = [frames, updates, timeDelta/1000.0]
self._infoText = "%d FPS, %d UPS [%0.2fms]" % (
frames, updates, timeDelta/1000.0
)
if self._debugMode:
print(self._infoText)
frames = 0
updates = 0
lastTimer = self.getTimeMicros()
if self._currentScene is not None:
self._gameScenes[self._currentScene].onExit()
tk.sys.exit(0)
def stopGame(self):
print("Attempting to close game...")
if (self._currentScene is not None
and not self._gameScenes[self._currentScene].willExit()):
return
if self._debugMode:
print("Closing game...")
self._running = False
def getTimeMicros(self):
return int(round(time.time() * 1000000))
def sleep(self, secs):
if self._mainWindow is None:
time.sleep(secs)
else:
self._mainWindow.update_idletasks()
self._mainWindow.after(int(1000 * secs), self._mainWindow.quit)
self._mainWindow.mainloop()