Hi Luke,

Thanks for that. From the code you've got there it looks like a list should
work fine. I haven't got the code I'd been trying to hand (essentially
assigning a new sprite to the list, but it sounds as though it was a python
problem, not pygame)

I shouldn't have any problems with this from now on. Thanks very much.
Fingers crossed!

>From your code, you could reference sprites[5] to get the sixth sprite,
right?

Thanks

Ben

2009/10/26 Luke Paireepinart <rabidpoob...@gmail.com>

>
>
> On Mon, Oct 26, 2009 at 4:43 AM, Ben Collier <bmcoll...@gmail.com> wrote:
>
>> Hi,
>>
>> I'm fairly new to pygame, certainly haven't used it much, and up until now
>> have been creating sprites by defining an extension to the sprite class and
>> then instantiating each sprite by assigning it as, for example:
>>
>> newsprite = NewSprite(250,250)
>>
>> ...with the arguments that the init method uses in brackets.
>>
>> If I want to create, say, 150 sprites, and simply add each one to a group
>> rather than having to have a distinct reference for each one, how do I do
>> it? I can't seem to find an example online and I've not had much luck adding
>> them to an array.
>>
>
> Why have you not been able to add them to a list?  (by the way, we call
> them "lists" not arrays in Python)
> Can you not just say
> locations = [(250, 250), (100,100), (300, 300)]
> sprites = [NewSprite(location) for location in locations]
> spritegroup = NewSpriteGroup()
> for sprite in sprites:
>     spritegroup.add(sprite)
>
> Note this is pseudocode as I don't remember the exact syntax to initialize
> sprites, etc. but you should get the idea.  Is there a problem doing it this
> way?
>
> (In the future, it would be better to say "I have tried it this way, and it
> did not work because" or "i have tried it this way and I am not sure why it
> did not work but here is what it did" or something like this, so we have
> some indication of what you have tried, and why it didn't work.
> See 
> http://catb.org/~esr/faqs/smart-questions.html<http://catb.org/%7Eesr/faqs/smart-questions.html>)
>
> -Luke
>
>

Reply via email to