Re: [pygame] Creating sprites on the fly?
Sure Make a default sprite. Hold a list of sprites in a dictionary-like class... def __getattr__(key): if self.sprites.has_key(key): return self.sprites[key] else: return self.default_sprite -- Thadeus On Mon, Apr 12, 2010 at 7:08 PM, Julian Marchant wrote: > Hi, I'm somewhat new to Python and very new to Pygame, so please bear with > me if I sound like an idiot. > > Is it possible to create sprites on-the-fly? > > In my load image function, I would like to add an option to create a simple > back-up sprite (a black rectangle will suffice) on-the-fly if the requested > sprite is unavailable, to allow the game to still run. > > --音本 > Website: http://onpon.co.nr/ >
Re: [pygame] Creating sprites on the fly?
Julian Marchant wrote: > Hi, I'm somewhat new to Python and very new to Pygame, so please bear with > me if I sound like an idiot. > > Is it possible to create sprites on-the-fly? > > In my load image function, I would like to add an option to create a simple > back-up sprite (a black rectangle will suffice) on-the-fly if the requested > sprite is unavailable, to allow the game to still run. Couldn't you just load a black rectangle at startup and use that in place of whatever sprite failed to load?
Re: [pygame] Creating sprites on the fly?
sounds like the point would be to have something to display in lieu of files being in the wrong place or non-existent. You'd have to do something like: create a pygame.Surface do Surface.fill()... etc... or use line drawing or something to create the sprite remember it for later, then if you do a try-catch block around your image load, a fail could then assign the default sprite instead. On Mon, Apr 12, 2010 at 5:52 PM, NBarnes wrote: > Julian Marchant wrote: > > > Hi, I'm somewhat new to Python and very new to Pygame, so please bear > with > > me if I sound like an idiot. > > > > Is it possible to create sprites on-the-fly? > > > > In my load image function, I would like to add an option to create a > simple > > back-up sprite (a black rectangle will suffice) on-the-fly if the > requested > > sprite is unavailable, to allow the game to still run. > > Couldn't you just load a black rectangle at startup and use that in > place of whatever sprite failed to load? >
Re: [pygame] Creating sprites on the fly?
OK, thanks! On Mon, Apr 12, 2010 at 8:58 PM, Lee Buckingham wrote: > sounds like the point would be to have something to display in lieu of > files being in the wrong place or non-existent. > > You'd have to do something like: > > create a pygame.Surface > do Surface.fill()... etc... or use line drawing or something to create the > sprite > remember it for later, then if you do a try-catch block around your image > load, a fail could then assign the default sprite instead. > > > On Mon, Apr 12, 2010 at 5:52 PM, NBarnes wrote: > >> Julian Marchant wrote: >> >> > Hi, I'm somewhat new to Python and very new to Pygame, so please bear >> with >> > me if I sound like an idiot. >> > >> > Is it possible to create sprites on-the-fly? >> > >> > In my load image function, I would like to add an option to create a >> simple >> > back-up sprite (a black rectangle will suffice) on-the-fly if the >> requested >> > sprite is unavailable, to allow the game to still run. >> >> Couldn't you just load a black rectangle at startup and use that in >> place of whatever sprite failed to load? >> > > -- Website: http://onpon.co.nr/