Re: [pygame] Sprite troubles
self.image, self.rect = loadImage('ground.bmp', -1) I seem to recognize that function from somewhere. The pygame.org cookbook? If so, -1 triggers the function to set the colorkey by picking the color from the pixel at point 0,0 in your image. If your image is a solid color, this would result in an image of essentially transparent pixels. Gumm
[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.
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 onp...@yahoo.com It's hard to help you when you haven't said what isn't working. -- *From:* Nathan BIAGINI nathan.o...@gmail.com *To:* pygame-users@seul.org *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.
Re: [pygame] Sprite troubles
RenderPlain? What's that? It's not mentioned here: http://www.pygame.org/docs/ref/sprite.html http://www.pygame.org/docs/ref/sprite.htmlI found it mentioned in some 2002 documentation. I think it might be obsolete. Not sure. I've been using pygame.sprite.OrderedUpdates. Dave http://www.pygame.org/docs/ref/sprite.html On Sat, Apr 30, 2011 at 3:53 PM, Nathan BIAGINI nathan.o...@gmail.comwrote: 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. -- “If anyone thinks the words ‘government’ and ‘efficiency’ belong in the same sentence, we have counseling available.” - Sen. Paul Tsongas (D-MA)
Re: [pygame] Sprite troubles
From what I gather, pygame.sprite.RenderPlain, in its current form, just points to pygame.sprite.Group. From: David Burton ncdave4l...@gmail.com To: pygame-users@seul.org; Nathan BIAGINI nathan.o...@gmail.com Sent: Sat, April 30, 2011 8:52:04 PM Subject: Re: [pygame] Sprite troubles RenderPlain? What's that? It's not mentioned here: http://www.pygame.org/docs/ref/sprite.html I found it mentioned in some 2002 documentation. I think it might be obsolete. Not sure. I've been using pygame.sprite.OrderedUpdates. Dave On Sat, Apr 30, 2011 at 3:53 PM, Nathan BIAGINI nathan.o...@gmail.com wrote: 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. -- “If anyone thinks the words ‘government’ and ‘efficiency’ belong in the same sentence, we have counseling available.” - Sen. Paul Tsongas (D-MA)
Re: [pygame] Sprite troubles
And what is loads? I think you might be working from some out-of-date docs, Nathan. I suggest that you use this (current) version of the pygame docs: http://www.pygame.org/docs/ref/sprite.html Here's a working (and almost minimal) pygame sprite-based program (tested with Python 3.1 and 2.6): import sys, pygame pygame.init() screen = pygame.display.set_mode((200,50), 0) arial = pygame.font.SysFont( 'arial,microsoftsansserif,courier', 16 ) sprite1 = pygame.sprite.Sprite() sprite1.image = arial.render('Hello, world!', True, (50,50,50)) sprite1.rect = sprite1.image.get_rect() sprite1.rect.topleft = (20,10) sprite_group = pygame.sprite.OrderedUpdates() sprite_group.add(sprite1) while True: event = pygame.event.wait() if (event.type == pygame.constants.QUIT): pygame.quit() sys.exit() screen.fill((240,240,240)) sprite_group.draw(screen) pygame.display.update() Here's almost the same program, but with an event loop that doesn't wait forever for an event; the changes are in red: *import sys, pygame* *pygame.init()* *clock = pygame.time.Clock()* *screen = pygame.display.set_mode((200,50), 0)* *arial = pygame.font.SysFont( 'arial,microsoftsansserif,courier', 16 )* *sprite1 = pygame.sprite.Sprite()* *sprite1.image = arial.render('Hello, world!', True, (50,50,50))* *sprite1.rect = sprite1.image.get_rect()* *sprite1.rect.topleft = (20,10)* *sprite_group = pygame.sprite.OrderedUpdates()* *sprite_group.add(sprite1)* *while True:* *for event in pygame.event.get():* *if (event.type == pygame.constants.QUIT):* *pygame.quit()* *sys.exit()* *screen.fill((240,240,240))* *sprite_group.draw(screen)* *pygame.display.update()* *clock.tick(60)* This is the same as the first version, except with a resizable window: * import sys, pygame pygame.init() scrsize = (200,50) screen = pygame.display.set_mode(scrsize, pygame.constants.RESIZABLE) arial = pygame.font.SysFont( 'arial,microsoftsansserif,courier', 16 ) sprite1 = pygame.sprite.Sprite() sprite1.image = arial.render('This window is resizable', True, (50,50,50)) sprite1.rect = sprite1.image.get_rect() sprite1.rect.topleft = (20,10) sprite_group = pygame.sprite.OrderedUpdates() sprite_group.add(sprite1) while True: event = pygame.event.wait() if (event.type == pygame.constants.QUIT): pygame.quit() sys.exit() elif event.type == pygame.constants.VIDEORESIZE: # this program is in a resizable main window; this event happens when it's resized scrsize = event.size # or (event.w, event.h) screen = pygame.display.set_mode(scrsize, pygame.constants.RESIZABLE) screen.fill((240,240,240)) sprite_group.draw(screen) pygame.display.update() * Dave On Sat, Apr 30, 2011 at 8:52 PM, David Burton ncdave4l...@gmail.com wrote: RenderPlain? What's that? It's not mentioned here: http://www.pygame.org/docs/ref/sprite.html http://www.pygame.org/docs/ref/sprite.htmlI found it mentioned in some 2002 documentation. I think it might be obsolete. Not sure. I've been using pygame.sprite.OrderedUpdates. Dave http://www.pygame.org/docs/ref/sprite.html On Sat, Apr 30, 2011 at 3:53 PM, Nathan BIAGINI nathan.o...@gmail.comwrote: 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.