1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

What is the best way to handle many enemies?

Discussion in 'Programming' started by Jacob Thrasher, Apr 24, 2019.

  1. Jacob Thrasher

    Jacob Thrasher Member

    Joined:
    Apr 24, 2019
    Posts:
    2
    In a platformer I am working on I would like to have various types of enemies, each with different abilities. I am unsure of what is the best way to go about including them so that the code runs as quickly and as smoothly as possible.

    I have two things in mind:
    -Creating a unique enemy object for each type of enemy and having the bullet object test for collisions with each type of enemy object. This would require a lot of collision checks, which I know slow the program.

    OR

    -Create one enemy object in which I can easily change the sprite indexes within in creation code. Then within the object, I would use various if statements to determine which type of enemy it is supposed to be and it would only access the necessary code for that instance. This would then require only one collision check from the bullet object, but I would also have to have a bunch of logical tests which could also slow the game down.

    It is really a matter of what will be the most efficient way for GameMaker to interpret the code. This is my first game so I am pretty inexperienced. I would like to avoid as many bad practices as I can while I learn.

    Thank you!
     
  2. Timothy

    Timothy Member

    Joined:
    Aug 7, 2016
    Posts:
    64
    Not true... they are still separate instances.

    An option that you did not consider, is using a common parent for our different enemy objects. Either way, your collision checks will remain the same and will scale with the amount of instances you create. GMS2 does some sort of spatial partitioning to make it more efficient... RTree I think.
     
  3. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    949
    Just create a parent object, say o_enemy_par, and make each enemy a child of that object. Then your collision code will test against that parent object.
     
    Robzoid likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice