0
votes

I am currently making Pong in pygame. I am doing this by creating sprites from images that i have already made. I have ran into a problem, how ever, in that my sprites won't show up on my screen. I sent the script to a friend who ran it on his machine, and substituted with his own images, and it worked fine. Does anyone have an idea what could be causing the sprites to now show on my machine?

creating the class:

class Paddle(pygame.sprite.Sprite):
img = "paddle.jpg"

def __init__(self):
    pygame.sprite.Sprite.__init__(self)
    self.image = pygame.image.load(self.img).convert()
    self.rect  = self.image.get_rect()

drawing it to the screen (as been added to the list called):

player1.place(10,10)
player2.place(50,50)
paddleList.draw(screen)

these are drawn outside the main loop. i understand that these wont update or anything as the game runs but they should still be statically placed on the screen. as stated before they showed on my friends machine. he used different images since i didnt send him the images i used to create the sprites, but they will not show up on my screen. I have even changed the images and nothing still shows.

EDIT: the main loop. all it does is continuesly draw the sprites. and has an exit event as of right now.

while True:
paddleList.draw(screen)
ballList.draw(screen)
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        pygame.quit()
        sys.exit() #ensures will quit on all systems. 
1
Have you verified that this is a display issue versus a loading issue (IE; where you assign self.image in your init function, does that actually get loaded with the image data?) - isick
do you get any stack traces while running? - Bartlomiej Lewandowski
I haven't thought of that and, I'm not really sure how to go about it. @isick - Stephen Stucky
its all error free. i have some print statements just to make sure the coordinates and the lists are being set. @BartlomiejLewandowski - Stephen Stucky
Another suggestion: get the images your friend used. Do they show-up in your machine? - skytreader

1 Answers

0
votes

You need to call pygame.display.flip() in your main loop, or it shall never refresh the screen. Replace the main loop with this:

while True:
    paddleList.draw(screen)
    ballList.draw(screen)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit() #ensures will quit on all systems.