473,572 Members | 3,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Runtime error when starting a game.

9 New Member
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?

Expand|Select|Wrap|Line Numbers
  1. import pygame, math, sys
  2. from pygame.locals import *
  3. from livewires import games
  5. # FPS
  6. clock = pygame.time.Clock()
  8. deltat = clock.tick(FRAMES_PER_SECOND)
  10. class Endzone(pygame.sprite.Sprite):
  11.     endzone_no_td = pygame.image.load('endzone.png')
  12.     endzone_td = pygame.image.load('endzone_td.png')
  14.     def __init__(self, position):
  15.         pygame.sprite.Sprite.__init__(self)
  16.         self.rect = pygame.Rect(self.endzone_no_td.get_rect())
  17.         self.rect.center = position
  19. class Player(pygame.sprite.Sprite):
  20.     player_image = pygame.image.load('49er.gif')
  21.     def __init__(self,position,team,pos_in_team):
  23.         if team == 'offense':
  24.             player_image = pygame.image.load('49er.gif')
  25.         else:
  26.             player_image = pygame.image.load('defense.gif')
  28.         """ if pos_in_team... """
  30.         pygame.sprite.Sprite.__init__(self)
  31.         self.rect = pygame.Rect(self.player_image.get_rect())
  32.         self.rect.center = position
  34. def game():
  35.     my_screen = games.Screen (width=1024, height=768)
  36.     bg = games.load_image("field.png")
  37.     my_screen.set_background(bg)
  38.     def_safety = Player((400,400),'defense','safety')
  39.     off_tight_end = Player((500,500),'offense','tigth_end')
  40.     my_screen.mainloop()
  42. game()
Mar 2 '09 #1
4 4998
469 Recognized Expert Contributor
Is your background solid green? Livewires may be converting the green pixels to transparent. Try this:
bg = games.load_imag e("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.
Mar 2 '09 #2
9 New Member
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>
File "...", line 47, in game
def_safety = Player('defense ',(40, 40))
File "...", line 36, in __init__
screen.blit(pla yer_image, self.position)
TypeError: invalid destination position for blit

And here is the code:
Expand|Select|Wrap|Line Numbers
  1. import pygame, math, sys
  2. from pygame.locals import *
  3. from livewires import games
  5. # FPS
  6. clock = pygame.time.Clock()
  8. deltat = clock.tick(FRAMES_PER_SECOND)
  10. screen = pygame.display.set_mode((1024, 768))
  13. class Player(pygame.sprite.Sprite):
  14.     player_image = pygame.image.load('49er.gif')
  15.     def __init__(self,team,position):
  16.         self.team = None
  17.         self.position = None
  19.         if self.team == 'offense':
  20.             player_image = pygame.image.load('49er.gif')
  21.         else:
  22.             player_image = pygame.image.load('defense.gif')
  24.         screen.blit(player_image, self.position)
  26. def game():
  27.     bg = pygame.image.load("field.png")
  28.     screen.blit(bg, (0,0))
  30.     #DEFENSE
  31.     def_safety = Player('defense',(40, 40))
  32.     def_safety.__init__()
  34.     # OFFENSE
  35.     off_tight_end = Player('offense',(100, 100))
  36.     def_safety.__init()
  38. game()
I have no idea why the "coordinate s" doesn't work...
Mar 3 '09 #3
469 Recognized Expert Contributor
Your init function does nothing with the arguments you pass it, and assigns the members to None. It should be
Expand|Select|Wrap|Line Numbers
  1.     def __init__(self,team,position):
  2.         self.team = team
  3.         self.position = position
I hope this helps.
Mar 3 '09 #4
9 New Member
Ah, that was kinda obvious :)
Thanks alot!
Mar 3 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: VinnieT | last post by:
I have a load balanced system that consists of 3 production servers. There are about 20 different applications that are used on these boxes. One of my applications in particular is used more than the others. Since updating 2 applications, I have had problems on the event log of the servers, following stopping of the aspnet_ws.exe process. ...
by: Mike P | last post by:
I will be passing my function a two dimensional array of varying length. Within that array is one data point, and the number of times it should loop through. So, for example, I might pass this to the function: example = new Array("A",2); example = new Array("Q",4); function loopIt(example);
by: bill_hounslow | last post by:
I'm trying to transfer data from one Sql Server into a table on another, using a simple INSERT query in an Access database with links to tables on both servers (the reasons for this are complicated but it IS the simplest solution, believe me). The 'Select' clause of the query works fine when run alone, but, when I run the INSERT query I get...
by: Oberon | last post by:
How do I deal with this? I am getting an error for each get in the Game class (see code below). In the simplified example below I have reduced this to just 3 fields, one which can be NULL. I have added 3 records to the table and ran the program but it fails with the error above. The application is supposed to create the hashtable of...
by: acb | last post by:
Hi, I have concluded an on-demand series of webcasts forming part of a series titled "Introduction to 2-D Video Game Development" that took place in 2005. The URL is at http://www.microsoft.com/events/series/msdnvideodev.mspx and the corresponding binaries can be found at...
by: NeedJavaHelp | last post by:
Hello everyone, first time poster here, bear with me. RuneScape is an online multiplayer game run by Java www.runescape.com. The game itself is run on the website and when you play the game for the first time, its files store on your pc. I've never had a problem untill its makers switched to Java Se (SUN Java). Normally, when you move to a...
by: whitehatmiracle | last post by:
SOS When i comile this program, im getting 13 errors all saying "prompt_for_bet and get_bet are not memebers of class Player" Where am i going wrong? Can anyone plzz enlighten me? Thnking u all in advance // gamble with Craps
by: xpun | last post by:
hey all So I decided to be a little ambitious over the summer and create the game of clue in c. I figured it would give my self a GOOD refresher of the language and further understand functions arrays objects etc.. Any way, I encountered a strange logic error and kinda put it to the side until now. This code is supposed to role the die,...
by: Saser | last post by:
Hi all bytes out there. I have a few little problems in my program. The program is supposed to help me to not spend too much time of my day at the computer ;) I play a game called Counter-Strike (CS) a lot, but I'm limited to 2 ½ hours a day, and a total of 4 hours a day. I have one button in my program which starts CS, and one button...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.