- May 2, 2017
- 2,854
- 7,710
So I have this code:
And the images using it are defined like this:
It's supposed to change the displayable's brightness when the key related to it is pressed and revert it back to normal when the key is released.
It only works on the screen that is highest in the stack, meaning if the screen has an "use" statement, it stops working for that screen.
If the screen being used also uses that displayable, it'll work on it, but if another screen is used down the code, it won't work for the previous screen either, so on and so forth.
So I guess what I'm looking for is a way for it to work on all screens currently displayed.
What am I missing?
Python:
class DdrNote(renpy.Displayable):
KEY_DICT = {
"left" : [pygame.K_LEFT, pygame.K_KP4, pygame.K_a],
"down" : [pygame.K_DOWN, pygame.K_KP2, pygame.K_s],
"up" : [pygame.K_UP, pygame.K_KP8, pygame.K_w],
"right" : [pygame.K_RIGHT, pygame.K_KP6, pygame.K_d]
}
def __init__(self, image, k):
super(renpy.Displayable,self).__init__()
self.image = image
self.k = k
self.brightness = 0.0
self.prev_brightness = 0.0
def render(self,width,height,st,at):
t = im.MatrixColor(self.image, im.matrix.brightness(self.brightness))
child_render = renpy.render(t, width, height, st, at)
cw, ch = child_render.get_size()
rv = renpy.Render(cw, ch)
rv.blit(child_render, (0,0))
renpy.redraw(self, 0)
return rv
def event(self, ev, x, y, st):
if ev.type == pygame.KEYDOWN:
if ev.key in self.KEY_DICT[self.k]:
self.brightness = 0.9
self.prev_brightness = 0.0
raise renpy.IgnoreEvent()
elif ev.type == pygame.KEYUP:
if ev.key in self.KEY_DICT[self.k]:
if self.brightness == 0.9:
self.brightness = 0.0
self.prev_brightness = 0.9
raise renpy.IgnoreEvent()
return None
Python:
DdrNote("images/left_arrow_frame.webp", "left")
It only works on the screen that is highest in the stack, meaning if the screen has an "use" statement, it stops working for that screen.
If the screen being used also uses that displayable, it'll work on it, but if another screen is used down the code, it won't work for the previous screen either, so on and so forth.
So I guess what I'm looking for is a way for it to work on all screens currently displayed.
What am I missing?
Last edited: