How do I make out of screen enemies inactive?

Get help using Construct 2

Post » Sat Jun 11, 2016 8:25 am

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.
B
55
S
18
G
5
Posts: 32
Reputation: 5,462

Post » Sat Jun 11, 2016 8:51 am

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.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Sat Jun 11, 2016 9:01 am

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.
B
55
S
18
G
5
Posts: 32
Reputation: 5,462

Post » Sat Jun 11, 2016 1:05 pm

Are you using the "Is on screen" condition in your enemies events ?
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Sat Jun 11, 2016 3:22 pm

granpa wrote: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
B
55
S
18
G
5
Posts: 32
Reputation: 5,462

Post » Sat Jun 11, 2016 5:13 pm

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 .
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Sat Jun 11, 2016 5:30 pm

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.
B
37
S
10
G
9
Posts: 212
Reputation: 6,970

Post » Sat Jun 11, 2016 7:24 pm

anty21ro wrote: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.
B
55
S
18
G
5
Posts: 32
Reputation: 5,462


Return to How do I....?

Who is online

Users browsing this forum: ASHKAR, brunopalermo, ItsAstro and 32 guests