Redrawing Custum Drawable periodically
Posted: Sat Sep 08, 2018 8:59 pm
I have a simple Tile-Based minigame in one of my games. Part of the gameplay involves zooming in/out and "moving" over the map.
I currently use a custom Drawable that manipulates a sprite. I use wasd for movement and q/e for zoomin in/out. The code to handle the events looks like this:
while this works, the drawable is only updates one time every second or so while keeping a button pressed, which makes the whole thing appear very laggy. So I'd like to manually call redraw every 1/20 second or so (performance should not be a real issue) to make the movement appear smooth. Just adding a redraw before the IgnoreEvent helps somewhat, but it requires causing some kind of event (like moving the mouse), which is kind of annoying.
I currently use a custom Drawable that manipulates a sprite. I use wasd for movement and q/e for zoomin in/out. The code to handle the events looks like this:
Code: Select all
def event(self, ev, x, y, st):
if ev.type == pygame.KEYDOWN:
if ev.key == pygame.K_q:
self.zooming_out = True
self.zoomrate = -0.1
renpy.redraw(self, 0)
if ev.key == pygame.K_e:
self.zooming_in = True
self.zoomrate = 0.1
renpy.redraw(self,0)
if ev.key == pygame.K_a:
self.panning = True
self.pan_x = 80
renpy.redraw(self, 0)
if ev.key == pygame.K_s:
self.panning = True
self.pan_y = -80
renpy.redraw(self, 0)
if ev.key == pygame.K_d:
self.panning = True
self.pan_x = -80
renpy.redraw(self, 0)
if ev.key == pygame.K_w:
self.panning = True
self.pan_y = 80
renpy.redraw(self, 0)
if ev.key == pygame.K_0:
return 0
if ev.type == pygame.KEYUP:
if ev.key == pygame.K_q:
self.zooming_out = False
self.zoomrate = 0
if ev.key == pygame.K_e:
self.zooming_in = False
self.zoomrate = 0
if ev.key == pygame.K_a:
self.panning = False
self.pan_x = 0
if ev.key == pygame.K_s:
self.panning = False
self.pan_y = 0
if ev.key == pygame.K_d:
self.panning = False
self.pan_x = 0
if ev.key == pygame.K_w:
self.panning = False
self.pan_y = 0
raise renpy.IgnoreEvent()