GameMaker My game freezes after i kill enemy

H

Hepero

Guest
So when i click play (f5) and start walking in my platformer game and kill enemy the game maker studio 2 runner freezes and i have to close it with task manager.
 

YoSniper

Member
My first thought: infinite loop.

Check your "for" and "while" loops, particularly in any collision code with the enemy object.

If you still can't find it, I recommend posting your code.
 
H

Hepero

Guest
My first thought: infinite loop.

Check your "for" and "while" loops, particularly in any collision code with the enemy object.

If you still can't find it, I recommend posting your code.
I got 2 "whiles" in enemy object (step event)
 
H

Hepero

Guest
Post the code.
So this is my Enemy Object step event:

vsp = vsp + grv;

//Horizontal collision
if (place_meeting(x+hsp,y,oWall))
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x = x + sign(hsp);
}
hsp = -hsp;
}
x = x + hsp;

//Vertical collision
if (place_meeting(x,y+vsp,oWall))
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;

//Animation
if (!place_meeting(x,y+1,oWall))
{
sprite_index = sEnemyA;
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = sEnemy;
}
else
{
sprite_index = sEnemyR;
}
}

if (hsp !=0) image_xscale = sign(hsp);
 

YoSniper

Member
So the problem does not occur until you kill the enemy, correct? When the enemy is idly walking around, there is no issue?

Please post the code that gets executed when you kill the enemy object, and if applicable, the enemy's Destroy Event.
 
H

Hepero

Guest
So this is enemy object death (step event):

if (done == 0)
{
vsp = vsp + grv;

//Horizontal collision
if (place_meeting(x+hsp,y,oWall))
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;

//Vertical collision
if (place_meeting(x,y+vsp,oWall))
{
if (vsp > 0)
{
done = 1;
image_index = 1;
}
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
}

and this is bullet object (collision with enemy object)

with (other)
{
hp--;
flash = 3;
hitfrom = other.direction;
}

instance_destroy();
 
H

Hepero

Guest
So the problem does not occur until you kill the enemy, correct? When the enemy is idly walking around, there is no issue?

Please post the code that gets executed when you kill the enemy object, and if applicable, the enemy's Destroy Event.
and no there is no issue when enemy is walking, only when i kill enemy
 

TheouAegis

Member
So are you changing sprites when the enemy dies or are you changing to a different object that uses a different Sprite than the one the enemy normally uses? if so, it sounds like your origin-to-bounds measurements are not equal, so when you kill the enemy it's turning into a Sprite that is automatically putting it into the ground. This forces an endless loop because if either of your speeds are 0, it can't move outside of the collision.
 
H

Hepero

Guest
So are you changing sprites when the enemy dies or are you changing to a different object that uses a different Sprite than the one the enemy normally uses? if so, it sounds like your origin-to-bounds measurements are not equal, so when you kill the enemy it's turning into a Sprite that is automatically putting it into the ground. This forces an endless loop because if either of your speeds are 0, it can't move outside of the collision.
yeah i use 2 objects for enemy. One is oEnemy that is just walking around and then when i kill it it changes to oDead (oDead has 2 sprites)
 

YoSniper

Member
Thought:

Remove the code that changes the enemy into oDead upon death, and instead just destroy the instance (for now.)

If this removes the freezing problem, then the problem code is in the oDead object. If it does not, then the problem is elsewhere in the oEnemy code.
 
H

Hepero

Guest
Thought:

Remove the code that changes the enemy into oDead upon death, and instead just destroy the instance (for now.)

If this removes the freezing problem, then the problem code is in the oDead object. If it does not, then the problem is elsewhere in the oEnemy code.
Thought:

Remove the code that changes the enemy into oDead upon death, and instead just destroy the instance (for now.)

If this removes the freezing problem, then the problem code is in the oDead object. If it does not, then the problem is elsewhere in the oEnemy code.
im not sure how to remove that bcs im newbie in coding and game developing, but im following the youtube tutorial from Shaun Spalding, maybe that will help you or smth
 

TheouAegis

Member
It's your sprites. Your dead object sprite is set up in such a way that it is forcing a collision. Set the dead object's sprite to <No Sprite> and see if that makes the freeze go away.
 
H

Hepero

Guest
It's your sprites. Your dead object sprite is set up in such a way that it is forcing a collision. Set the dead object's sprite to <No Sprite> and see if that makes the freeze go away.
Ok so it worked but how do i make the death object?
 
H

Hepero

Guest
Thought:

Remove the code that changes the enemy into oDead upon death, and instead just destroy the instance (for now.)

If this removes the freezing problem, then the problem code is in the oDead object. If it does not, then the problem is elsewhere in the oEnemy code.
Ok i have this code

if (hp <= 0)
{
with (instance_create_layer(x,y,layer,oDead))
{
direction = other.hitfrom;
hsp = lengthdir_x(3,direction);
vsp = lengthdir_y(3,direction)-2;
if (sign(hsp) != 0) image_xscale = sign(hsp) * other.size;
image_yscale = other.size;
}
instance_destroy();
}

And when i removed the code i had this code:

if (hp <= 0)
{

instance_destroy();
}

And it worked, but now i dont have the dead animation for the enemy.
 

Yal

šŸ§ *penguin noises*
GMC Elder
You can change the COLLISION MASK independently of the SPRITE, set the collision mask of the death object to either the normal enemy sprite (since it didn't have collisions) or to a 1x1 pixel sprite whose only pixel is 100% transparent (a null-mask that will never collide with anything). Former lets you have it collide if you want, latter ensures it won't get stuck but could look uglier, but both lets you keep the death sprite without it getting permanently stuck.
 
Top