Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been following a tutorial to make my first Pong clone. Here is the tutorial:

When I try to run it I get this error message:

Traceback (most recent call last): File "/Users//Documents/Pygame/", line 133, in game = Game() File "/Users//Documents/Pygame/", line 66, in init self.sprites.add(self.leftpaddle) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/", line 319, in add sprite.add_internal(self) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/", line 147, in add_internal self.__g[group] = 0 AttributeError: 'Paddle' object has no attribute 'Sprite_g'

I could not figure out why, my code looks pretty much the same as the one in the tutorial.

    # Pong V2 OOP
import pygame, sys, random, os, math
from pygame.locals import *

class Paddle(pygame.sprite.Sprite):
    def __init__(self, xy):
        #initialize the pygame sprite part
        self.image = pygame.image.load(os.path.join('images','pong_paddle.gif'))
        self.rect = self.image.get_rect()

        #set position
        self.rect.centerx, self.rect.centery = xy

        #movement speed of paddle
        self.movementspeed = 5

        #current velocity
        self.velocity = 0

    def up(self):
        self.velocity -= self.movementspeed

    def down(self):
        self.velocity += self.movementspeed

    def move(self, dy):
        if self.rect.bottom + dy > 400:
            self.rect.bottom = 400
        elif + dy < 0:
   = 0
            self.rect.y += dy

    def update(self):

class Game(object):
    def __init__(self):

        self.screen = pygame.display.set_mode((800,400),0,32)

        pygame.display.set_caption('Pong V2')
        self.clock = pygame.time.Clock()

        pygame.event.set_allowed([QUIT, KEYDOWN, KEYUP])

        # set background:
        self.background = pygame.Surface((800,400))

        # draw line in middle
        pygame.draw.line(self.background, (0,0,0), (400,0), (400,400), 2)
        self.screen.blit(self.background, (0,0))


        # a sprite rendering group for our ball and paddles
        self.sprites = pygame.sprite.RenderUpdates()

        # create our paddles and add to sprite group
        self.leftpaddle = Paddle((50,200))
        self.rightpaddle = Paddle((750,200))

    def run(self):
        print('Starting Event Loop')

        running = True

        while running:

            running = self.handleEvents()

            #Update title with fps
            pygame.display.set_caption('Pygame Tutorial 2 - Basic   %d fps' % self.clock.get_fps())

            # update sprites
            for sprite in self.sprites:

            # render sprites
            self.sprites.clear(self.screen, self.background)
            dirty = self.sprites.draw(self.screen)

            # blit 

        print('Quitting, thanks for playing!')

    def handleEvents(self):

        # poll for events
        for event in pygame.event.get():
            if event.type == QUIT:
                return False
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    return False

                # paddle control
                if event.key == K_UP:
                if event.key == K_DOWN:
                if event.key == K_w:
                if event.key == K_s:
            elif event.type == KEYUP:
                # paddle control
                if event.key == K_w:
                if event.key == K_s:

                if event.key == K_UP:
                if event.key == K_DOWN:

        return True

if __name__ == '__main__':
    game = Game()

Can anyone help me?

share|improve this question

Look here:

When you subclass Sprite, you must call this pygame.sprite.Sprite.__init__(self) before you add the sprite to any groups, or you will get an error.

That seems to be what is missing in order to make Paddle a proper subclass of Sprite.

share|improve this answer
I tried adding pygame.sprite.Sprite.__init__(self), but still got an error: line 64, in init pygame.sprite.Sprite.__init__(Paddle) TypeError: unbound method __init__() must be called with Sprite instance as first argument (got type instance instead) – rcs May 3 '13 at 0:10
Nevermind, got it to work! Thanks! – rcs May 3 '13 at 1:18
In order to complete the usefulness of this question for others could you please write out exactly what you did to make it work? – aaaaaaaaaaaa May 3 '13 at 6:13
+1 to @eBusiness - please show us the working code to exapnd on the solution and accept eBusiness' answer if it helped find it. – Blue May 3 '13 at 14:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.