1

The image I have for the main character of the game will not show up on the screen.

I've tried making sure my gameDisplay.fill command comes before the jumper(x,y) function so that it doesn't overwrite the character. This seems to be the issue for every other thread I could find. It still doesn't work.

import sys

pygame.init()

windowWidth = 800
windowHeight = 600

black = (0,0,0)
white = (255,255,255)

x = (windowWidth * 0.45)
y = (windowHeight * 0.8)

def jumper(x,y):
    gameDisplay.blit(jumperNormal, (x,y))

jumperNormal = pygame.image.load('jumper.png')

gameDisplay = pygame.display.set_mode((windowWidth, windowHeight))

pygame.display.set_caption("Jumperman")

clock = pygame.time.Clock()

running = True

while running:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    gameDisplay.fill(white)
    jumper(x, y)
    pygame.display.flip()
    clock.tick(60)


pygame.quit()
pygame.display.quit()
sys.exit()

What I'm trying to do is get the character to follow mouse coordinates on the screen, but first I need to get the image to appear on the screen. I'm following this guy's tutorial on Pygame: https://pythonprogramming.net/displaying-images-pygame/?completed=/pygame-python-3-part-1-intro/

I even copied and pasted his code into another program and the image didn't even pop up then, even though in his tutorial, it did.

TheDog
  • 11
  • 2
  • What happens when you run? Do you get an error? Blank screen? No window? The code seems to be correct (haven't tested though). – Ted Klein Bergman Apr 08 '19 at 03:49
  • @TedKleinBergman It just appears as a white screen. No image appears at all. – TheDog Apr 08 '19 at 03:52
  • This code works for me, once I added `import pygame`. Is your .png file `jumper.png` OK? (It's not transparent, or something like an all-white image on a white-background right?) – Kingsley Apr 08 '19 at 03:54
  • @Kingsley Yes. This is what my window looks like: https://imgur.com/Kk5DlCw – TheDog Apr 08 '19 at 03:57
  • @Kingsley My png isn't good. My friend designed it, and I have no idea what he did with it. It's identical to the racecar I copied from the guy's website in the fact that the background is transparent. Very interesting, I have no idea what's wrong with it. – TheDog Apr 08 '19 at 03:59
  • Load it into some kind of image editing program (like "The GIMP" https://www.gimp.org/) and re-save it as a new PNG. – Kingsley Apr 08 '19 at 04:00
  • Did you get this to work ? – Kingsley Apr 08 '19 at 23:46

0 Answers0