Looking for a better way to limit bad guys on screen

jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
edited November -1 in Working with GS (Mac)
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.

Comments

  • design219design219 Member Posts: 2,273
    I have the exact same thing in my game, and noticed the same issue, so I added a rule that when the score reached a certain point, another timer would clear the enemy count every thirty seconds. With the random spawning, odds are against the count getting much above 12, and it makes the game get harder. Working very well for me.
  • PhoticsPhotics Member Posts: 4,172
    With my game, I have the enemies (rocks) destroyed once they leave the screen. It doesn't always seem to work, as sometimes they wrap anyway, but it was good enough for me.
  • GamexcbGamexcb Member Posts: 179
    I have a game that uses this same concept!
    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
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    design219 - I had tried that too :)

    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?
  • synthesissynthesis Member Posts: 1,693
    If I read correctly, you need to use a <= logic comparison instead of = when checking whether to respawn or not.

    Then just before respawning...do a double check if the present counter is accurate before executing the spawn.
  • rebumprebump Member Posts: 1,058
    @mul: Gamexcb is showing you the logic that is in the spawned actors (aka enemies). Each time one spawns or dies, it keeps track of the count and its own place in the count. You would then only spawn when the game level attribute is at or below a certain threshold (likely stored in yet another game level attribute).

    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).
Sign In or Register to comment.