Object Activation Conundrum

quattj

Member
I have a master game controller, it runs this script in the begin step.
GML:
function room_activate()
{
    instance_deactivate_region(view_left(), view_top(), view_width(), view_height(), false, true);
    instance_activate_object(obj_base_block);
    instance_deactivate_region(view_left()-80, view_top()-80, view_width()+160, view_height()+160, false, true);
    instance_activate_object(obj_tracker);
    instance_activate_object(obj_weapon);
    instance_activate_object(obj_weapon_onehit);
    instance_activate_region(view_left(), view_top(), view_width(), view_height(), true);
    instance_activate_object(obj_base_ctrl);
    instance_activate_object(obj_base_ship);
    instance_activate_object(obj_checkpoint);
    instance_activate_object(obj_player_continuespot);
    instance_activate_object(obj_deactivator);
}
It deactivates anything outside of the view, then reactivates all blocks (stage pieces), then deactivates what remains in an area 80 larger than the view in each direction so there is a buffer for anything that bleeds over the edges and is still active. This keeps all blocks around the play area "existing" when enemies and such are then reactivated in the view.

My problem comes when there are enemies above the top of the screen, but still in the active zone, but they shouldn't technically "be there" until the stage scrolls upwards a little more.

To try to solve this, I created a stand-alone deactivator, which has a check in its begin step, step, and end step for enemies at its location.
Code:
baddie = instance_place(x, y, obj_weapontarget);
if (baddie)
    instance_deactivate_object(baddie);
This "appears" to work. I can not see the enemies on the screen until the deactivator object is destroyed. Buuut, there is a skeleton that throws bones on a timer. Once the stage scrolls to where the skeleton is properly formed (deactivator destroyed) there is a huge pile of projectile bones waiting to explode everywhere, bones that should not exist if the skeleton was properly deactivated.

Looking for suggestions on how I can tame this beast. I was thinking of adding a variable to enemies for keeping them deactive, but I think that wouldn't work because if they are not active, the variable can't be read anyway.
 

quattj

Member
Got everyone puzzled too I see :p

I tried various things to get it to cooperate. It seems that activating and deactivating something still gives it enough time to perform some actions, which is no good.

There is a "time freeze" object in the game that temporarily freezes all enemies. I modified the custom deactivator to instead set the "time freeze" in the enemies that contact the deactivator. This kept them from moving and performing any actions. But they were still targetable by weapons, so certain things could still happen to them while they were not technically on screen. (Look, skeleton feet! Die, skeleton feet!) I updated it to disallow them from getting hurt, but then they could still be tracked, and turned to ice (which kills them).

Just before I went to bed last night I got a brilliant idea: instead of trying to stop the enemy from doing anything, just destroy it and make a copy of it when it should officially appear on screen. I tried it out, and it works perfect.

So there is a deactivator, 32x32 pixels. Place it over enemy that is being stubborn and appearing too early. Give it a collision with said enemy. Get the object type and position of the enemy. Destroy the enemy. When the deactivator comes on screen, create a new copy of the enemy at the same coordinates as the old, destroy itself, and viola!

In the collision:
GML:
minion = other.object_index;
minion_x = other.x;
minion_y = other.y;
minion_depth = other.depth;
with (other)
    instance_destroy();
In the destroy (when the deactivator comes on screen):
GML:
instance_create_depth(minion_x, minion_y, minion_depth, minion);
 
Top