-
Python (
http://www.daniweb.com/forums/forum114.html)
| tomtetlaw | Dec 3rd, 2008 4:15 am | |
| Yet another pygame help thread Im testing out blit() and i ran into this error:
Traceback (most recent call last):
File "/home/tom/Desktop/pygame/test/main.py", line 15, in <module>
screen.blit('image.jpg', (10,10))
TypeError: argument 1 must be pygame.Surface, not str
this is my code:
import pygame
pygame.init()
running = 1
while running == 1:
screen = pygame.display.set_mode((800, 600))
event = pygame.event.poll()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 0
image = pygame.image.load('image.jpg').convert()
screen.blit('image.jpg', (10,10))
screen.fill((0, 0, 0))
pygame.display.flip()
any ideas? |
| jlm699 | Dec 3rd, 2008 6:54 am | |
| Re: Yet another pygame help thread screen.blit(image, (10,10)) I think.. |
| tomtetlaw | Dec 4th, 2008 5:48 am | |
| 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. |
| vegaseat | Dec 4th, 2008 3:40 pm | |
| Re: Yet another pygame help thread Generally its done this way ...
import pygame
# optional
pygame.init()
# create the screen (or pygame window)
screen = pygame.display.set_mode((800, 600))
# fill the screen black (default)
screen.fill((0, 0, 0))
# pick an image you have (.bmp .jpg .png .gif)
# if the image file is not in the working folder,
# use the full pathname
# convert() is optional for higher speed
image = pygame.image.load('image.jpg').convert()
# draw image and position the image ulc at x=10, y=10
screen.blit(image, (10,10))
# nothing gets displayed until one updates the screen
pygame.display.flip()
# start event loop and wait until
# the user clicks on the window corner x
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
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 ... |
| tomtetlaw | Dec 5th, 2008 8:02 pm | |
| Re: Yet another pygame help thread THanks man, that solved it all XD. |
| All times are GMT -4. The time now is 4:01 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC