Woah, that's a lot of questions.
Are you certain that you have enemies outside the view disabled?
Yes, I've drawn the amount of objects on the screen and it decreases when I offscreen the enemies.
Are you certain your not accidentally calling place_meeting many times per enemy per step? Or maybe there is another reason the game is lagging?
This is the code I'm using.
Code:
var hspd_final=hspd+hspd_carry;
hspd_carry=0;
if(place_meeting(x+hspd_final,y,par_solid)){
yplus=4;
while(place_meeting(x+hspd_final,y-yplus,obSlope)&&yplus<abs(1.25*max(hspd_final))) yplus++;
if(place_meeting(x+hspd_final,y-yplus,par_solid)){
while(!place_meeting(x+sign(hspd_final),y,par_solid)){
x+=sign(hspd_final);
}
hspd=0;
hspd_final=0
} else {
y-=yplus;
}
}
x+=hspd_final;
// Slopes (going down)
if !place_meeting(x,y,par_solid) && vspd >= 0 && place_meeting(x,y+4+abs(1.5*hspd_final),par_solid)
{
while(!place_meeting(x,y+1,par_solid))
{
y += 1;
}
while(place_meeting(x,y,par_solid)) y--;
}
Have you tried removing place_meeting to make sure that it is in fact causing the lag?
I have ran the profiler in the debugger and it said that the enemy object was taking in the most memory.
And how much lag, just a bit or a lot?
Without the enemies the FPS counter shows 50 to 60 fps. With the enemies the counter shows a value around 30 to 40 fps.
What device are you testing on?
Windows
What are you doing with the collision?
Checking if the enemy is going to collide with a solid object, then if so, move it as close to the solid object as possible and then reset the values.
Are you looping at all after the collision? Are you looping through collisions?
Yes.
There are so many possibilities why you could be experiencing lag it's difficult to say.
Yes, there indeed are many possibilities. But after running the profiler I have found the thing that is causing the most lag of all.
However, this is the profiler. If we do the math right it calls scHspd() 6187 times in 46 steps.
There are 135 enemies on the screen. 30889 times place_meeting seems incredibly much at first, but we run place_meeting 30889 / 6187 = 5 times per step per scHspd() call. And we call scHspd() 135 times per step, because there are 135 enemies on the screen. You might expect from reading the code I put above, that I call it more than 5 times per step, but some place_meetings only are triggered when an if statement returns true.
I hope this gave you enough understanding of the situation and more importantly, I hope this gave you enough information to help me out.