I need help with Pygame

I need help with Pygame

Postby CeroZeta » Thu Sep 08, 2016 12:05 pm

Hi, first of all! Sorry about my English! I don´t speak very well (but I will learn a lot writing in this forum :P)
I am learning to program in python and pygame and I have an error. I don´t know why :( if someone can help me i will be really happy xD

Code: Select all
import pygame,sys
from pygame.locals import *
#global  variables
width = 900
high = 480

class Rocket(pygame.sprite.Sprite):
   """Class for Rocket"""

   def __init__(self):
      self.ImageRocket = pygame.image.load('Images/rocket.jpg')

      self.rect = slef.ImageRocket.get_rect()
      self.rect.centerx = width/2
      self.rect.centery = high-30

      self.shootingList = []
      self.Health = True

   def shoot(self):

   def draw(self,surface):
      surface.blit(self.ImageRocket, self.rect)

def SpaceInvader():
   screen = pygame.display.set_mode((width,high))
   pygame.display.set_caption("Space Invader")

   player = Rocket

   while True:
      for evento in pygame.event.get():
         if evento.type == QUIT:




Traceback (most recent call last):
File "C:\Pygame\Space_Invaders\Project.py", line 43, in <module>
File "C:\Pygame\Space_Invaders\Project.py", line 40, in SpaceInvader
TypeError: unbound method draw() must be called with Rocket instance as first argument (got Surface instance instead)

Posts: 1
Joined: Thu Sep 08, 2016 11:45 am

Re: I need help with Pygame

Postby metulburr » Thu Sep 08, 2016 12:29 pm

Code: Select all
   player = Rocket

You are not creating an object, but just transferring the class to another variable. You need to add parenthesis after Rocket

Code: Select all
   player = Rocket()
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests