I'm trying to change the state of my sprite (transforming from human to penguin) by pressing K_DOWN. For some reason I can only trigger the event by changing the state in Keydown, but I want to do it with Keyup, as Keydown causes the sprite to constantly shift as the key is pressed down. What am I doing wrong?
if event.type == pygame.KEYUP:
self.x = 0
if keys[pygame.K_DOWN]:
print(self.is_penguin)
if self.is_penguin == False:
self.is_penguin = True
else:
self.is_penguin = False
Animation function
if self.is_penguin == False:
if self.look_left:
if self.rect.bottom >= 470:
self.state_index = 0
else:
self.state_index = 1
self.image = self.states[self.state_index]
if self.x < 0 and self.rect.bottom == 470:
self.image = self.walk_states[int(self.walk_idx)]
else:
if self.rect.bottom >= 470:
self.states_R_index = 0
else:
self.states_R_index = 1
self.image = self.states_R[self.states_R_index]
if self.x > 0 and self.rect.bottom == 470:
self.image = self.walk_states_R[int(self.walk_idx)]
else:
self.image = self.penguin_states[0]