[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Sprite troubles



Yeah that's true... Sorry about that. My problem is that the sprite in the RenderGroup is simply not drawn.

2011/4/30 Julian Marchant <onpon4@xxxxxxxxx>
It's hard to help you when you haven't said what isn't working.


From: Nathan BIAGINI <nathan.open@xxxxxxxxx>
To: pygame-users@xxxxxxxx
Sent: Sat, April 30, 2011 3:53:29 PM
Subject: [pygame] Sprite troubles

Hi everyone,

it sounds like a stupid question but i have written a really simple program where i just want to add a sprite to a sprite group and then draw the containing of this group.

Here is the main code :


import pygame
from sprites import Node

pygame.init()

screen = pygame.display.set_mode((640, 480))
node_group = pygame.sprite.RenderPlain()

node = Node((156, 234), 0)
node_group.add(node)

while 1:
        node_group.update()
        node_group.draw(screen)

        pygame.display.flip()

And here is my sprite class :

import pygame
from pygame.locals import *
from loads import loadImage

class Node(pygame.sprite.Sprite):
        '''
        Node class represent the sprite of each node of the
        map. So, one instance of Node is created for each
        node.
        '''

        def __init__(self, pos, node_type):
                pygame.sprite.Sprite.__init__(self)

                self.pos = pos
                self.node_type = node_type

                if self.node_type == 0:
                        self.image, self.rect = loadImage('ground.bmp', -1)

                elif self.node_type == 1:
                        self.image, self.rect = loadImage('wall.bmp', -1)

                elif self.node_type == 2:
                        self.image, self.rect = loadImage('hole.bmp', -1)

                self.rect.topleft = pos

        def update(self):
                pass

I maybe a bit tired but i can't see what i m doing wrong...

Thanks for your help.