This pygame code does not work. All I am trying to do is load images to test an animation.
import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("pesto anchovy")
plright = [pygame.image.load('Player/pl_idle.png'), pygame.image.load('Player/pl_move.png')]
char = pygame.image.load('pl_idle.png')
run = True
while run :
pygame.time.delay(100)
win.blit(plright[1], (50, 50))
pygame.display.update()
pygame.time.delay(100)
win.blit(plright[0], (50, 50))
pygame.display.update()
please help.
plright = [pygame.image.load('Player/pl_idle.png'), pygame.image.load('Player/pl_move.png')]
I think what you are doing here is making a list of load commands, but not running them. Try loading them separately.
it works outside of the loop, but not in it, which causes obvious problems
Do you get an error, or does nothing happen? If it works outside the loop then the loading works, it's the animation that doesn't.
nothing works, not even a single, non-animated image.
I obviously don't have the images, so I replaced them with just surfaces filled with a color:
plright = []
first = pygame.Surface((25, 25))
first.fill((255, 0, 100))
plright.append(first)
second = pygame.Surface((25, 25))
second.fill((0, 0, 200))
plright.append(second)
The rest of your code I didn't change, and it ran fine (the colors shifted back and forth). However, because you aren't checking for events, I had to force-kill python to stop it lol.
I've made a few changes, maybe this will help:
import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("pesto anchovy")
plright = []
first = pygame.Surface((25, 25))
first.fill((255, 0, 100))
plright.append(first)
second = pygame.Surface((25, 25))
second.fill((0, 0, 200))
plright.append(second)
#char = pygame.image.load('pl_idle.png')
run = True
clock = pygame.time.Clock()
active_index = 0
while run:
for ev in pygame.event.get():
if ev.type == pygame.QUIT:
run = False
win.blit(plright[active_index], (50, 50))
active_index = (active_index+1) % len(plright)
pygame.display.flip()
clock.tick(10)