So I'm trying to make a function inside a "scene" class to have text pop up whenever you press "z" and continue to be blitted for a while.
If I use the pygame.key.get_pressed() it only blitz while Z is pressed. I want it to pop up when Z is pressed and continue to stay on screen for a while.
##This is inside the "scene" class##
def printText(self, surface):
if self.counter < 20:
text = pygame.font.SysFont("Pixelated Regular", 30)
label = text.render("Hello", 0, (0,0,0,))
surface.blit(label, (100,100))
self.counter += 1
##This is inside the main##
if key[pygame.K_z]:
robsHouse.printText(screen)
Just in case I didnt make it clear before: I basically want it the text to be blitted for a couple of frames even after I let go of "z".
Thanks in advance.
What i would do is create a boolean to define wheter the button was pressed or not
Here is an example:
then at then when you want the text to go away set
self.pressed
toFalse
and it will stop being blittedlike this:
That way once the counter ends the text will dissapear
Hope that helps!