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

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 <nbarnes@xxxxxxxxx> wrote:
Julian Marchant <onpon4@xxxxxxxxx> 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?