943,706 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1133
  • Python RSS
Dec 3rd, 2008
0

Yet another pygame help thread

Expand Post »
Im testing out blit() and i ran into this error:
python Syntax (Toggle Plain Text)
  1. Traceback (most recent call last):
  2. File "/home/tom/Desktop/pygame/test/main.py", line 15, in <module>
  3. screen.blit('image.jpg', (10,10))
  4. TypeError: argument 1 must be pygame.Surface, not str
  5.  
  6. this is my code:
  7.  
  8. import pygame
  9. pygame.init()
  10. running = 1
  11. while running == 1:
  12. screen = pygame.display.set_mode((800, 600))
  13. event = pygame.event.poll()
  14. for event in pygame.event.get():
  15. if event.type == pygame.QUIT:
  16. running = 0
  17. image = pygame.image.load('image.jpg').convert()
  18. screen.blit('image.jpg', (10,10))
  19. screen.fill((0, 0, 0))
  20. pygame.display.flip()

any ideas?
Last edited by tomtetlaw; Dec 3rd, 2008 at 4:28 am.
Similar Threads
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008
Dec 3rd, 2008
1

Re: Yet another pygame help thread

python Syntax (Toggle Plain Text)
  1. screen.blit(image, (10,10))
I think..
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008
Dec 4th, 2008
0

Re: Yet another pygame help thread

Nah, that didnt work, but it did get rid of the error, just dosnt show the pic on screen.
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008
Dec 4th, 2008
0

Re: Yet another pygame help thread

Generally its done this way ...
python Syntax (Toggle Plain Text)
  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 ...
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Dec 5th, 2008
0

Re: Yet another pygame help thread

THanks man, that solved it all XD.
Reputation Points: 9
Solved Threads: 5
Posting Pro
tomtetlaw is offline Offline
591 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Play Sounds at different Speeds
Next Thread in Python Forum Timeline: Mario clone





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC