1
Python Help!
So I'm making a simply game in pygame and python. But I've ran into an error. Basically when I run the game, all that's meant to happen so far is for a rocket to be infront of a blue background. But instead, I get a black background with nothing on it... Until I close out of it. When I close out of the game for a split second I see a blue background and part of my ship in the bottom left hand corner. Any fixes?
CODE :
I don't get any errors in the run script either.
CODE :
Click to reveal
import pygame
pygame.init()
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
blue = (0,57,230)
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Random Name Game...')
clock = pygame.time.Clock()
carImg = pygame.image.load('ship.png')
def car(x,y):
gameDisplay.blit(carImg,(x,y))
x = (display_width * 0.45)
y = (display_height * 0.8)
dead = False
while not dead:
for event in pygame.event.get():
if event.type == pygame.QUIT:
dead = True
gameDisplay.fill(blue)
car(x,y)
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()
pygame.init()
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
blue = (0,57,230)
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Random Name Game...')
clock = pygame.time.Clock()
carImg = pygame.image.load('ship.png')
def car(x,y):
gameDisplay.blit(carImg,(x,y))
x = (display_width * 0.45)
y = (display_height * 0.8)
dead = False
while not dead:
for event in pygame.event.get():
if event.type == pygame.QUIT:
dead = True
gameDisplay.fill(blue)
car(x,y)
pygame.display.update()
clock.tick(60)
pygame.quit()
quit()
I don't get any errors in the run script either.
6
[deleted]
Oh np at all, I just assumed you knew python. Thanks for helping tho
[deleted]
Ok yeah that worked :p I had a few command lines in a loop and stuff. Thanks
One more question though, I thought my ship was too big, so I resized it in paint.net and saved it as sprite (It's a png file). It's on my desktop, which is where my script is also saved. But when I do: carImg = pygame.image.load('sprite.png') it says:
Traceback (most recent call last):
File "C:\Users\My_Username\Desktop\pythongame.py", line 17, in <module>
carImg = pygame.image.load('sprite.png')
pygame.error: Couldn't open sprite.png
One more question though, I thought my ship was too big, so I resized it in paint.net and saved it as sprite (It's a png file). It's on my desktop, which is where my script is also saved. But when I do: carImg = pygame.image.load('sprite.png') it says:
Traceback (most recent call last):
File "C:\Users\My_Username\Desktop\pythongame.py", line 17, in <module>
carImg = pygame.image.load('sprite.png')
pygame.error: Couldn't open sprite.png
I thought "True" and "False" were spelled with the first letter uppercase though? Or did it change in Python 3?
Nop, True and False have to be capitalized. But he was right in saying that I had some lines in the wrong place.
