Code: Select all
init python:
import math
import pygame
test_image = Image("img.png")
class KeyRoll(renpy.Displayable):
def __init__(self,image):
super(renpy.Displayable,self).__init__()
self.start_image = image
self.rotation = 0
def render(self,width,height,st,at):
render = renpy.Render(0, 0)
self.img = Transform(self.start_image, xanchor=0.5,yanchor=0.5,rotate=self.rotation)
child_render = renpy.render(self.img, 0, 0, st, at)
render.blit(child_render, (0,0))
return render
def event(self, ev, x, y, st):
roll = {pygame.K_LEFT: -3, pygame.K_RIGHT: 3}
pressed = pygame.key.get_pressed()
while pygame.key.get_pressed == pygame.K_LEFT or pygame.key.get_pressed == pygame.K_RIGHT:
for m in (roll[key] for key in roll if pressed[key]):
self.rotation += m
self.img = Transform(self.start_image, xanchor=0.5,yanchor=0.5,rotate=self.rotation)
renpy.redraw(self, 0)
pygame.time.wait(33)
screen test:
add KeyRoll(test_image):
xanchor 0.5
yanchor 0.5
label start:
"before"
call screen test
"after"
return
Removing the while statement and dedenting accordingly will rotate the image per key press.
Replacing the while conditions with True ignores key input, gives zero rotation, and will eventually crash.
I strongly suspect my issue lies in my loop conditions, but despite my efforts, and half a dozen other people's threads on press-hold behavior, I cant seem to work it out. any suggestions?