You're only updating 5 frames a second, so yu should expect delays of up to 0.2s, and if you tap the key fast enough it won't register. Why not change the 5 to 50 or something?
I apologize in advance for posting 43 lines of code, but I can't figure out
where on Earth the trouble is coming from.
When I run this code, the keys do exactly what I'd like, but I'm noticing a
delay of a few tenths of a second between when I press the key and when the
sound of the step is played. Further, sometimes when I tap an arrow key
quickly, the player won't even take a step.
Can anyone please tell me what I'm doing wrong? This looks sound to me.
from sound_lib.stream import FileStream
from sound_lib.output import Output
self.x = 10
self.step = FileStream(file="sounds/step.ogg")
self.step.pan = 0
self.step_time = 0.25
self.last_step_time = 0.0
def move(self, dir):
if time.time() - self.last_step_time <= self.step_time:
if self.x + dir < 1 or self.x + dir > 20:
self.x += dir
if dir > 0:
self.step.pan += 0.1
self.step.pan -= 0.1
self.last_step_time = time.time()
clock = pygame.time.Clock()
o = Output()
guy = Player()
screen = pygame.display.set_mode((640, 400))
keys = pygame.key.get_pressed()
for event in pygame.event.get(): pass
if __name__ == '__main__':