Python Forum
[PyGame] pygame image loading error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] pygame image loading error
#1
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.
Reply
#2
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.
Reply
#3
it works outside of the loop, but not in it, which causes obvious problems
Reply
#4
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.
Reply
#5
nothing works, not even a single, non-animated image.
Reply
#6
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)
Reply
#7
Thank you, that worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pygame Zero - no actor image toiling_away 2 1,784 Oct-14-2022, 12:16 AM
Last Post: toiling_away
  How to make an image move in relation to another in PYGAME CompleteNewb 1 2,299 Nov-10-2021, 03:38 PM
Last Post: metulburr
  [PyGame] Pygame attribute error djwilson0495 3 3,928 Feb-18-2021, 03:34 PM
Last Post: michael1789
Big Grin Error installing Pygame-Zero dpa2007 1 3,162 Dec-26-2020, 03:50 PM
Last Post: MK_CodingSpace
  [PyGame] Error: Couldn't open image DotGuy 2 7,172 May-18-2020, 06:19 PM
Last Post: DotGuy
  pygame error in my clicker game CrazyMakes 2 2,542 Apr-19-2020, 03:04 AM
Last Post: Windspar
  Error to install pygame skp 1 3,476 Apr-14-2020, 05:17 PM
Last Post: joe_momma
  open cv ->pygame: turn image into location Gamedeveloper 1 2,054 Jan-20-2020, 05:00 PM
Last Post: michael1789
  installing pygame error pylab 1 4,255 Dec-31-2019, 05:44 PM
Last Post: pylab
  Problem with music - Pygame.error GaseBall 1 3,188 Nov-28-2019, 07:46 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020