How do I make out of screen enemies inactive?

0 favourites
  • 8 posts
From the Asset Store
Save hours of work by resizing items on your game screens.
  • Hi,

    In a platform game. I made many types of enemies. Each enemy has its own behaviors and some of them has un-regular behaviors (I made them AI) so I can't make their behaviors inactive. how can I suspend all those enemies if they are out of the screen? I notice that some of them shoots the player even if it is out of the screen. Is there an event that can make the object inactive?

    Thanks in advance.

  • Question...why can't you just destroy them once their off screen and respawn them later?

    I'm not at my laptop right now but i think you can pause them. Sorry, cant remember the exact event. If you get too many sprites that are still created off screen this may hog some memory.

  • I don't want the way of destroying them and then create them cause each one is positioned in a certain place and the map of the platform is big. So, it is hard to create them in exact position using events.

  • Are you using the "Is on screen" condition in your enemies events ?

  • Are you using the "Is on screen" condition in your enemies events ?

    "Is On screen" condition is used if I want to destroy the enemies outside the screen but I don't want to destroy them I just don't want them to be active if they are outside the screen.

    Please, If you have any idea on how to use this condition in this situation.

    The situation is that I don't want to destroy the enemies outside the screen and at the same time I don't want them to be active. Maybe you say that C2 is intelligent to make inactive of outside screen sprites but what I see that those enemies (sprites) are interactive even if it is outside the screen.

    Thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't know how you are controlling your enemies , but you can invert the Is on screen condition and then disable the behavior if the condition is true .

  • You could create an instance variable for the enemies called "state" for example. When is set to 1 you set the behavior group of the enemy to be active and when is set to 0 you set it inactive. So, when enemy "Is on screen" set enemy state to 1 else set it to 0.

  • You could create an instance variable for the enemies called "state" for example. When is set to 1 you set the behavior group of the enemy to be active and when is set to 0 you set it inactive. So, when enemy "Is on screen" set enemy state to 1 else set it to 0.

    Thanks anty21ro . This is a good solution. I also thought of another solution that I make a dummy sprite for each enemy and this dummy has only one function. If the dummy in screen then it spawn the enemy once, otherwise the enemy is destroyed.

    When I post my question, I though that there might already be an event that suspend the sprite if it is out of screen.

    Anyways, Your solution is better than mine since it doesn't drain the resources of the CPU.

    Thank you all guys. I appreciate your help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)