GameMaker render distance

S

stepup2000

Guest
Im trying to make a render distance (turning off all the instances when they are to far away)
code:
//create
alarm_set(0, 30);
instance_deactivate_all(true);


//alarm 0
alarm_set(0, 30);
instance_activate_region(x - 200, y - 200, x + 200, y - 200, true)
instance_deactivate_region(x - 200, y - 200, x + 200, y - 200, false, true)


i didnt have the time to test this but this should work. now the problem is that at the beginning of the game there will be a huge frame drop because the game has to deactivate tons of objects. i had the idea to fix this with:


alarm 1
alarm_set(1, 5);
inst = instance_nearest(x, y, all)
if distance_to_object(inst) > 200 {
instance_deactivate_object(inst)
}

but the probem with this is that this takes a really long time. does anyone have any idea how to optimize this and fix the problems? thanks in advance.
 

jo-thijs

Member
Im trying to make a render distance (turning off all the instances when they are to far away)
code:
//create
alarm_set(0, 30);
instance_deactivate_all(true);


//alarm 0
alarm_set(0, 30);
instance_activate_region(x - 200, y - 200, x + 200, y - 200, true)
instance_deactivate_region(x - 200, y - 200, x + 200, y - 200, false, true)


i didnt have the time to test this but this should work. now the problem is that at the beginning of the game there will be a huge frame drop because the game has to deactivate tons of objects. i had the idea to fix this with:


alarm 1
alarm_set(1, 5);
inst = instance_nearest(x, y, all)
if distance_to_object(inst) > 200 {
instance_deactivate_object(inst)
}

but the probem with this is that this takes a really long time. does anyone have any idea how to optimize this and fix the problems? thanks in advance.
Deactivating instances is something entirely different from a render distance.
If you are only seeking to implement a render distance that doesn't draw sprites outside the view, GameMaker already does this for you, so you don't need to do anything.
If you are seeking to skip the entire draw events of instances outside the view, you should be making them invisible, not deactivate them (although the odds are you'll only lose performance with that).
If you truely want to skip executing anything for instances outside the view, then you should be deactivating them.

Now, you said that you haven't tested it yet, but that you think there will be a huge frame drop at the beginning of the game.
Can you confirm this frame drop actually occurs?
If you have so many instances that instance_deactivate_region is this slow in going through all of them, then performing a step event for all of them should almost be as bad and you won't want to delay deactivating instances.
The solution would probably be to find a way to not have to create all instances in the room at once.
How to achieve this depends on your project.
 
S

stepup2000

Guest
Deactivating instances is something entirely different from a render distance.
If you are only seeking to implement a render distance that doesn't draw sprites outside the view, GameMaker already does this for you, so you don't need to do anything.
If you are seeking to skip the entire draw events of instances outside the view, you should be making them invisible, not deactivate them (although the odds are you'll only lose performance with that).
If you truely want to skip executing anything for instances outside the view, then you should be deactivating them.

Now, you said that you haven't tested it yet, but that you think there will be a huge frame drop at the beginning of the game.
Can you confirm this frame drop actually occurs?
If you have so many instances that instance_deactivate_region is this slow in going through all of them, then performing a step event for all of them should almost be as bad and you won't want to delay deactivating instances.
The solution would probably be to find a way to not have to create all instances in the room at once.
How to achieve this depends on your project.
im sorry for my late reply, i didnt expect anyone to reply to this tread anymore. I need to deactivate the objects and i thought that was called render distance but it is something else (idk what) the framedrop in the beginning isnt to bad so i can get away with it for now. but i decided that if i ever needed to change it i should do something with a loading bar, and then create all the different kind of instances one by one (lets say walls first, then items, then props etc.)
 
Top