GMS 2 2D Platformer spawn code

Discussion in 'Programming' started by Andrei, Apr 14, 2019.

  1. Andrei

    Andrei Member

    Joined:
    Jun 24, 2016
    Posts:
    8
    Let's get straight to the game.
    I have build a big level currently the camera is fixated on the play and you can only see a small portion of the level at once, but that's not the problem.
    The problem are the enemies, I know the basics you just place them in the rom and they will appear when you start the game, the problem is some enemies are more advanced than others (can fly or shoot projectiles) so after a while you will meet them near the start of the rom even if you placed them at the end. What I wanna do is make them spawn when I'm close to them, I know I can use a code like //if (distance_to_object(objPlayer) <192) enemy_spawn// but I can't do that since they will spawn on the map in the first place.
    I want to place them in the rom with game maker as normal but they need to appear in the game when I'm close enough, that's what I want to do.
    Any ideas?
     
  2. Lady Glitch

    Lady Glitch Member

    Joined:
    Feb 10, 2019
    Posts:
    20
    I'm not sure I understood you correctly. This might work:

    Enemy Create Event:
    Code:
    IsActive = false;
    Enemy Step Event:
    Code:
    if IsActive
    {
        // Pretty much all of your Step Event Code
    }
    else
    {
        if distance_to_object(objPlayer) <= 192
        {
            IsActive = true;
        }
    }
     
  3. Andrei

    Andrei Member

    Joined:
    Jun 24, 2016
    Posts:
    8
    Hey thanks, It works perfectly, why didn't I thought of this :D
     
    Lady Glitch 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