View Single Post
Join Date: Oct 2004
Posts: 3,858
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 867
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Yet another pygame help thread

 
0
  #4
Dec 4th, 2008
Generally its done this way ...
  1. import pygame
  2.  
  3. # optional
  4. pygame.init()
  5.  
  6. # create the screen (or pygame window)
  7. screen = pygame.display.set_mode((800, 600))
  8.  
  9. # fill the screen black (default)
  10. screen.fill((0, 0, 0))
  11.  
  12. # pick an image you have (.bmp .jpg .png .gif)
  13. # if the image file is not in the working folder,
  14. # use the full pathname
  15. # convert() is optional for higher speed
  16. image = pygame.image.load('image.jpg').convert()
  17.  
  18. # draw image and position the image ulc at x=10, y=10
  19. screen.blit(image, (10,10))
  20.  
  21. # nothing gets displayed until one updates the screen
  22. pygame.display.flip()
  23.  
  24. # start event loop and wait until
  25. # the user clicks on the window corner x
  26. while True:
  27. for event in pygame.event.get():
  28. if event.type == pygame.QUIT:
  29. raise SystemExit
You had some indentation problems, and filled the screen black after drawing the image. Also, don't put the file loading into the event loop or it will keep loading and loading ...
May 'the Google' be with you!
Reply With Quote