Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What would be the best way to load enemies in a level. For example take Mario, are enemies rendered at their x,y positions as the game is loaded or when the player walks past a specific x value. Wouldn't this mean that you would have multiple if conditions checking whether the player has reached a specific x value to spawn an enemy; this doesn't seem like a very good solution to this problem at least to me.

What would be the recommended way?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

The originals absolutely loaded the enemies as you got close to them, as loading all enemies at once was likely beyond the memory constraints of the older gaming hardware. A lot of crazy and now unnecessary tricks were used back then to minimize memory usage.

Today, I would still opt to loading them on demand as you neared their spawn locations, as it gives more flexibility. Also, you'll notice that in games like Mario, the enemies always appear in the same place moving the same way; so even if you loade them in advance, you'd have to disable their movement until Mario got close enough.

There should be no question about the number of "if" statements, as you should absolutely not be writing code to spawn specific enemies on a specific map. Write a data file to describe your level and enemy spawn points, and then write a single generic block of code to check to see if Mario has gotten close to any unspawned enemies from the data list.

As much as possible, make everything data driven. Hard coded logic makes development slower and harder and, as you pointed out, just isn't a good solution to this problem.

share|improve this answer
    
Thanks for the great answer! –  Sun May 28 '12 at 20:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.