Redrawing Custum Drawable periodically

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Noisyedge
Newbie
Posts: 5
Joined: Mon Sep 03, 2018 1:54 pm
Github: Noisyedge
Contact:

Redrawing Custum Drawable periodically

#1 Post by Noisyedge »

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:

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()
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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]