'why does the image not move when the keys are pressed
part of the code in the Gg class related to movement:
class Gg(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.image.load('gg.png')
self.rect = self.image.get_rect()
self.rect.center = (81, 239)
def move(self):
pressed_keys = pygame.key.get_pressed()
if pressed_keys[K_UP]:
self.rect.move_ip(0, speed_gg_up)
if pressed_keys[K_DOWN]:
self.rect.move_ip(0, speed_gg_down)
G = Gg()
gg_sprites = pygame.sprite.Group()
gg_sprites.add(G)
this is part of the code in the game loop:
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
screen.fill(GREY)
for entity in gg_sprites:
screen.blit(entity.image, entity.rect)
entity.move
FramePerSec.tick(FPS)
gg_sprites.draw(screen)
pygame.display.update()
I have an image, but when I press the up and/or down keys, the image does not move. the code does not issue errors. I don't understand what I'm doing wrong
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
