Added time delta
This commit is contained in:
@ -26,6 +26,10 @@ class Game:
|
|||||||
# The games serface
|
# The games serface
|
||||||
self.surf = pygame.Surface(self._surf.size)
|
self.surf = pygame.Surface(self._surf.size)
|
||||||
self.size = self.surf.size
|
self.size = self.surf.size
|
||||||
|
# Used for time delta, stores when the last frame was drawn
|
||||||
|
self._lastFrame = time.perf_counter()
|
||||||
|
# How many seconds it's been between frames
|
||||||
|
self.timeDelta = 0
|
||||||
# Pre-render semi-transparent black surface
|
# Pre-render semi-transparent black surface
|
||||||
self._dimSurf = pygame.Surface(self._surf.size)
|
self._dimSurf = pygame.Surface(self._surf.size)
|
||||||
self._dimSurf.set_alpha(128)
|
self._dimSurf.set_alpha(128)
|
||||||
@ -70,6 +74,9 @@ class Game:
|
|||||||
self._surf.blit(self._dimSurf, (0, 0))
|
self._surf.blit(self._dimSurf, (0, 0))
|
||||||
self._surf.blit(centre(self._popupMenu, self.size), (0, 0))
|
self._surf.blit(centre(self._popupMenu, self.size), (0, 0))
|
||||||
|
|
||||||
|
self.timeDelta = time.perf_counter() - self._lastFrame
|
||||||
|
self._lastFrame = time.perf_counter()
|
||||||
|
|
||||||
def onEvent(self, event):
|
def onEvent(self, event):
|
||||||
"""
|
"""
|
||||||
Intended to be overridden by the game developer.
|
Intended to be overridden by the game developer.
|
||||||
|
|||||||
Reference in New Issue
Block a user