Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411990 Posts in 69441 Topics- by 58486 Members - Latest Member: Fuimus

June 17, 2024, 12:50:47 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Pygame multiple object instances
Pages: [1]
Print
Author Topic: Pygame multiple object instances  (Read 1513 times)
Ping
Level 0
*



View Profile
« on: January 01, 2009, 12:05:25 PM »

Hey guys, I'm takin' another swing at this whole game programming thing.

I'm easing myself in with a basic shmup written in pygame, my tool of choice.

However, I've hit something of a snag: how do you instantiate objects on-the-fly?

What I mean is this: I need to be able to create "bullet" objects without having to worry about creating a predetermined number of them beforehand.

Same with enemies, really.

How do you guys handle this?
Logged
Mr. Yes
Level 5
*****



View Profile WWW
« Reply #1 on: January 01, 2009, 12:31:23 PM »

Been a while since I used Python, and I've never used Pygame before at all, but I think I've got it. Seems like you could create them by adding them into a list of bullets or enemies on the fly, and then loop through that list whenever you want to access each bullet or enemy, for example when you're drawing them all. (unless there's some Python specific way of doing this kind of thing, I completely forget everything about Python at this point)
Logged

Ping
Level 0
*



View Profile
« Reply #2 on: January 01, 2009, 12:57:23 PM »

Oh. Duh. I already loop through sprite lists anyhow; dunno why it didn't occur to me to just add them to a list.

Thanks.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic