本文整理匯總了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()