Looking for a better way to limit bad guys on screen
In my game I'm trying to limit the amount of bad guys on screen at once to help with performance. Right now I've got a counter, every time a bad guy is spawned, the counter is increased by 1, when the counter hits 8, the spawners stop. When a bad guy is killed, the counter is reduced by 1. It kinda works. The problem is if I kill two guys at once, the counter only seems to reduce by 1, after about 1/2 the level, it's off by 4.
Anyone have a better idea on how to get around this? I'd like a consistent way of tracking how many bad guys are on screen.
Anyone have a better idea on how to get around this? I'd like a consistent way of tracking how many bad guys are on screen.
Comments
Okay It works 100%!
When an enemy is spawned the enemy sets a local var, I called it Run ID, I set Run ID to zero.
Then I have a global var, I called it Enemy ID.
Now in the actor's code you make a group called ID.
Then add a rule
If (game.Enemy ID = 0 and Self.Run ID = 0){
then
Set self.Run ID to 1
Set game.Enemy ID = game.Enemy ID + 1
}
If (game.Enemy ID = 1 and Self.Run ID = 0){
then
Set self.Run ID to 1
Set game.Enemy ID = game.Enemy ID + 1
}
If (game.Enemy ID = 2 and Self.Run ID = 0){
then
Set self.Run ID to 1
game.Enemy ID to game.Enemy ID - 1
Destroy Actor
}
And when ever you have the enemy dies decrease game.Enemy ID by 1.
It requires some work but it works 100%
Hope it helps!
-Gamexcb
Gamexcb - that looks interesting, it looks like the code you have above has a limit of 2 actors at once, am I reading that right?
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
Then just before respawning...do a double check if the present counter is accurate before executing the spawn.
The game level attribute is just acting as an ID counter/holder/high-water-mark so you can keep track of enemy instances. I recommended a similar solution for a related problem a while back but I cannot seem to find the post (although Gamexcb has provided the mock-up which is more than my description was).