Legacy GM To many objects make lag. /SOLVED/

MicroKiss

Member
So I have an idea in this game where you can't see anything but you can shoot pixels to discover your mapNévtelen.png
ABut the problem is that if I play for a while there will be to many pixels which are slowing down the game.
Here is the game : https://ufile.io/73guu
Could you please suggest solutions for me ? thx
 

MicroKiss

Member
destroy the instances when they collide with a wall or when they get out of the room
Yeah that would solve the problem but the point of the game is that you can only see what you discover and you discover by thos pixels.
when the pixels collide with the wall they stop there so you can se where walls are
 

DesArts

Member
When the player shoots a wall draw the point to a surface rather than keeping the object. Alternatively add the coordinates and colour to a controller array which holds all the points of impact and draws them, only needing one object to show every point.

First method would be faster but more volatile.
 

MicroKiss

Member
then limit the player's ammunition or make the player pickup the ammo they just used
Hmm yeah the ammunition counter is a good idea, but there is no way somehow stop the pixels working and just be one sprite whih would use less calculating power ?
 

MicroKiss

Member
When the player shoots a wall draw the point to a surface rather than keeping the object. Alternatively add the coordinates and colour to a controller array which holds all the points of impact and draws them, only needing one object to show every point.

First method would be faster but more volatile.
So I should make a 2D array which contains the x and y coordinates of the discovered points and then i should draw those point with a for loop ?
 

DesArts

Member
That would definitely work. Remember to delete the bullet when the point of impact is recorded.

How many bullets can you shoot and how rapidly?
 

Simon Gust

Member
If it's less than 0.5 bullets / frame it's already an improvement on the drawing to surface part. Just make sure that the bullets don't fly forever and out of bounds
 

MicroKiss

Member
That would definitely work. Remember to delete the bullet when the point of impact is recorded.

How many bullets can you shoot and how rapidly?
You can shoot 8 bullets in every frame (60 fps)
and btw could you help me a bit wtih this array ?
i have these 2 codes
this one is in the pixel's code :
STEP :
if position_meeting(x,y,obj_solid){
global.array[global.array+1,0] = self.x;
global.array[global.array+1,1] = self.y;
global.array += 1;
instance_destroy();
}}
and these one in the pixel drawer's code :
CREATE :

global.array = 0
global.array[0,0] = 0
global.array[0,1] = 0
//////////////////////////////////////////////////////////////////////
DRAW:
if global.array > 1 {
for (i = 1; i < global.array; i += 1)
{
draw_sprite(spr_pixel,0,global.array[i,0],global.array[i,1])
}}

*/*//*/*/*/*/*/*/*//*/*/
But i get this problem here :

Push :: Execution Error - Variable Index [1,1] out of range [1,-1] - -5.array(100000,32001)
at gml_Object_obj_pixeldraw_DrawEvent_1 (line 4) - draw_sprite(spr_pixel,0,global.array[i,0],global.array[i,1])
############################################################################################
Sorry for my miserable coding skills but i haven't really worked whit arrays
 

DesArts

Member
8 bullets every frame is probably going to cause some issues.

You might want to consider not even using objects for the bullets.

As for your array issue, make sure you create your array by doing
global.array[0, 0] = 0;
global.array[0, 1] = 0;

You cannot use global.array+1 to find the array's size, use array_height_2d(global.array)+1.
 

MicroKiss

Member
8 bullets every frame is probably going to cause some issues.

You might want to consider not even using objects for the bullets.
but it works rly fine for like half a min but i guess after that there are just more than 10'000 objects and that's the prob
 

DesArts

Member
but it works rly fine for like half a min but i guess after that there are just more than 10'000 objects and that's the prob
Check my reply again I added stuff about the array.

And yeah that's why you might want to not use objects for them any more. You'll probably need an array for the landed bullets and something like a list or something else for the active ones.

The landed bullet array might actually get so big that it too becomes slow so I might even recommend drawing them to a surface upon impact, a surface will not grow slower no matter how many stationary bullets are on it, but surfaces require much more care.
 

MicroKiss

Member
The problem is solved thanks to Desix:
this is the proper use of 2d arrays if some1 wants to save coordinates :

Code:
if position_meeting(x,y,obj_solid){
global.array[array_height_2d(global.array),0] = x;
global.array[array_height_2d(global.array)-1,1] = y;
instance_destroy();
}
 
Top