How to make Gif's directly work on pygame without using sprites?

29 Views Asked by At

So I'm trying to make a sample where you get to choose the Pokemon starter, and it plays the sound using pygame. But the problem is that when I use gifs, they are in a single line. The code also contains classes for Pokemon, which display the frame width, and a class for each Pokemon to play the sound and get displayed.


charmander_gif = pygame.image.load(os.path.join("images", "charmander.gif"))
bulbasaur_gif = pygame.image.load(os.path.join("images", "bulbasaur.gif"))
squirtle_gif = pygame.image.load(os.path.join("images", "squirtle.gif"))

def game():
    charmander_frame = 0
    bulbasaur_frame = 0
    squirtle_frame = 0
    clock = pygame.time.Clock()
    selected_pokemon = None

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                mouse_x, mouse_y = pygame.mouse.get_pos()
                if charmander_rect.collidepoint(mouse_x, mouse_y):
                    selected_pokemon = Charmander()
                elif bulbasaur_rect.collidepoint(mouse_x, mouse_y):
                    selected_pokemon = Bulbasaur()
                elif squirtle_rect.collidepoint(mouse_x, mouse_y):
                    selected_pokemon = Squirtle()

        screen.blit(background_image, (0, 0))

        charmander_frame = (charmander_frame + 1) % 52
        bulbasaur_frame = (bulbasaur_frame + 1) % 52
        squirtle_frame = (squirtle_frame + 1) % 52

        charmander_rect = screen.blit(charmander_gif, (50, 400), (charmander_frame * charmander_gif.get_width()//10, 0, charmander_gif.get_width() // 10, HEIGHT))
        bulbasaur_rect = screen.blit(bulbasaur_gif, (350, 400), (bulbasaur_frame * bulbasaur_gif.get_width()//10, 0, bulbasaur_gif.get_width() // 10, HEIGHT))
        squirtle_rect = screen.blit(squirtle_gif, (650, 400), (squirtle_frame * squirtle_gif.get_width()//10, 0, squirtle_gif.get_width() // 10, HEIGHT))

        if selected_pokemon:
            selected_pokemon.display(300, 200)  
            selected_pokemon.play_sound()

        pygame.display.flip()
        clock.tick(FPS)

if __name__ == "__main__":
    game()


This is my snippet of the code. The single-line animation that moves

0

There are 0 best solutions below