quickest way to spawn in an enemy

Started by
1 comment, last by Code Mole 20 years ago
I''m using direct X 9, and what i''m doing so far is as follows. during the loading screen (for the level) I load in all the textures I''m going to use for the characters/level. I then make out a bad guy template for each of the different bad guys in the level. so now when I need to spawn a bad guy (since there could be multiple instances of the same bad guy at once!)I just copy over from the template, give the bad guy a unique ID and set the pointers to the proper textures. This way I''m not allocating any new textures. This get up works, execpt, there is a 1/2 second freeze when ever a new bad guy is spawned into play. (very bad!). Now there is alot of data in the bad guy class and thats probably why it takes so long to copy over. I might have missed something that will make the code faster. I was wondering if anyone had a smarter way of spawning in enemies? or do I have the right idea and just need to work the bugs out? ~code mole~
Advertisement
Well, depending upon your implementation, you might want to use what is known as a "recyclable array". Basically, create a certain number of "bad guys" at loading time, the max amount the player will ever encounter. Then set them all "inactive" (having no impact in the game, not visible). When you need a "bad guy" give him his unique qualities (position, etc) and set him "active". When he dies, set him "inactive" again. Contain this all in a recylable array class.
I guess thats where I was trying to go with my code in the first place and just didn''t get the idea right, that helps alot!

Thanks Pixel!

~code mole~

This topic is closed to new replies.

Advertisement