• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help swapping objects

K

Kurthinhio

Guest
Hi, i'm doing a 2D space shooter game. i'm trying to make 3 powerups.
i have: obj_bombs, obj_laser, obj_barrier, obj_player, obj_powerup
what i want to do is: when obj_powerup collides with obj_player while obj_bombs exists, replace obj_bombs with obj_laser.
the same but now, while obj_laser exists replace with obj_barrier.
and the same but now, while obj_barrier exists replace with obj_bombs.
any ideas to hel me figure this out?
thx
 

Lady Glitch

Member
I would do it this way:

Create a new object (let's call it par_changer) and assign it as a parent for your obj_bombs, obj_laser and obj_barrier.

Create Event (obj_bombs, obj_laser, obj_barrier)
Code:
Replacer = *object*; // Change *object* to obj_bombs/obj_laser/obj_barrier
Replace = false;
Step Event (obj_player)
Code:
with (instance_place(x, y, obj_powerup))
{
    with(par_changer)
    {
        Replace = true;
    }
    instance_destroy();
}
Step Event (par_changer)
Code:
if Replace
{
    instance_create_layer(x, y, "LayerID", Replacer);
    instance_destroy(self);
}
 
Last edited:

Filkata

Member
How about a simpler suggestion? In the collision event of the object to be changed:

Code:
instance_create_depth(x, y, 0, newObj); // here put the object to replace with, so for bombs put obj_laser, etc.
instance_destroy(self);
 
Top