Runtime error when starting a game. | Newbie | | Join Date: Nov 2008
Posts: 9
| |
All i wanna do at this point is to test the (soon to be) game and see that the correct sprites are were they are supposed to be.
When i run the game the background is black instead of the green color of my field.png, no other sprites are visible and after a while i get a Runtime error and the game crashes.
Any ideas? -
import pygame, math, sys
-
from pygame.locals import *
-
from livewires import games
-
-
# FPS
-
clock = pygame.time.Clock()
-
FRAMES_PER_SECOND = 30
-
deltat = clock.tick(FRAMES_PER_SECOND)
-
-
class Endzone(pygame.sprite.Sprite):
-
endzone_no_td = pygame.image.load('endzone.png')
-
endzone_td = pygame.image.load('endzone_td.png')
-
-
def __init__(self, position):
-
pygame.sprite.Sprite.__init__(self)
-
self.rect = pygame.Rect(self.endzone_no_td.get_rect())
-
self.rect.center = position
-
-
class Player(pygame.sprite.Sprite):
-
player_image = pygame.image.load('49er.gif')
-
def __init__(self,position,team,pos_in_team):
-
-
if team == 'offense':
-
player_image = pygame.image.load('49er.gif')
-
else:
-
player_image = pygame.image.load('defense.gif')
-
-
""" if pos_in_team... """
-
-
pygame.sprite.Sprite.__init__(self)
-
self.rect = pygame.Rect(self.player_image.get_rect())
-
self.rect.center = position
-
-
def game():
-
my_screen = games.Screen (width=1024, height=768)
-
bg = games.load_image("field.png")
-
my_screen.set_background(bg)
-
def_safety = Player((400,400),'defense','safety')
-
off_tight_end = Player((500,500),'offense','tigth_end')
-
my_screen.mainloop()
-
-
game()
-
|  | Expert | | Join Date: Mar 2008 Location: California
Posts: 478
| | | re: Runtime error when starting a game.
Is your background solid green? Livewires may be converting the green pixels to transparent. Try this:
bg = games.load_image("field.png", transparent = False)
If that works, we'll have to work on your sprites next. I don't think loading the player images with pygame is a good idea. If you're going to be using livewires, you might as well let it do that stuff for you. Or you could just use pygame without livewires.
Good luck with the game.
| | Newbie | | Join Date: Nov 2008
Posts: 9
| | | re: Runtime error when starting a game.
Thanks for the tip, it took care of the runtime error.
I've played around a bit more and now i have another problem.
I get the following error: Traceback (most recent call last):
File "...", line 54, in <module>
game()
File "...", line 47, in game
def_safety = Player('defense',(40, 40))
File "...", line 36, in __init__
screen.blit(player_image, self.position)
TypeError: invalid destination position for blit
And here is the code: - import pygame, math, sys
-
from pygame.locals import *
-
from livewires import games
-
-
# FPS
-
clock = pygame.time.Clock()
-
FRAMES_PER_SECOND = 30
-
deltat = clock.tick(FRAMES_PER_SECOND)
-
-
screen = pygame.display.set_mode((1024, 768))
-
-
-
class Player(pygame.sprite.Sprite):
-
player_image = pygame.image.load('49er.gif')
-
def __init__(self,team,position):
-
self.team = None
-
self.position = None
-
-
if self.team == 'offense':
-
player_image = pygame.image.load('49er.gif')
-
else:
-
player_image = pygame.image.load('defense.gif')
-
-
screen.blit(player_image, self.position)
-
-
def game():
-
bg = pygame.image.load("field.png")
-
screen.blit(bg, (0,0))
-
-
#DEFENSE
-
def_safety = Player('defense',(40, 40))
-
def_safety.__init__()
-
-
# OFFENSE
-
off_tight_end = Player('offense',(100, 100))
-
def_safety.__init()
-
-
game()
-
I have no idea why the "coordinates" doesn't work...
|  | Expert | | Join Date: Mar 2008 Location: California
Posts: 478
| | | re: Runtime error when starting a game.
Your init function does nothing with the arguments you pass it, and assigns the members to None. It should be - def __init__(self,team,position):
-
self.team = team
-
self.position = position
I hope this helps.
| | Newbie | | Join Date: Nov 2008
Posts: 9
| | | re: Runtime error when starting a game.
Ah, that was kinda obvious :)
Thanks alot!
|  | | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,562 network members.
|