• 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!

Object Spawning/Despawning System Based on View Region

How would you do an object spawning system? It needs to get rid of objects in the room not onscreen, keep original xy position, and the object index to recreate them when inside the view region. I need a more efficient system than instance deactivate, so I can put many more instances in the room editor without the in game level slowing down. I probably need some objects to not be destroyed off-screen as well.
 

Fabseven

Member
I think you donot have another choice thant instance desactivate BUT be sure to instance_desactivate only one time a objet out of the view
+ use a alarm of something to delay your code/functions/script used to desactivate yours objets.
(delay may be speed_room or something)

So if your view is moving instead of desactivate instantanly your objets out of the view there will be speed_room waiting before,
So if your view is moving 100 times your code will be activated 100/speed_room times instead of 100 times,
if speed_room is at 30 (default value) your will update your objets 3 times instead of 100 , witch is 97% less, not bad ?
 
I think you donot have another choice thant instance desactivate BUT be sure to instance_desactivate only one time a objet out of the view
+ use a alarm of something to delay your code/functions/script used to desactivate yours objets.
(delay may be speed_room or something)

So if your view is moving instead of desactivate instantanly your objets out of the view there will be speed_room waiting before,
So if your view is moving 100 times your code will be activated 100/speed_room times instead of 100 times,
if speed_room is at 30 (default value) your will update your objets 3 times instead of 100 , witch is 97% less, not bad ?
Won't that slow down the frames where it does do the deactivation just as much leading to uneven slowdown? There would still be lag that way, wouldn't there?
 
A

AlphaRedDragon

Guest
Code:
if(room != rm_boss_test)
{
instance_deactivate_object(obj_block_top_left)
instance_deactivate_object(obj_block_bottom_right)
instance_deactivate_object(obj_block_middle_right)
instance_deactivate_object(obj_block_bottom_middle)
instance_deactivate_object(obj_block_top_middle)
instance_deactivate_object(obj_block_middle_left)
instance_deactivate_object(obj_block_middle)
instance_deactivate_object(obj_block_bottom_left)
instance_deactivate_object(obj_block_top_right)
instance_deactivate_object(obj_skeleton)
instance_deactivate_object(obj_super_skeleton)
instance_deactivate_object(obj_spider)
instance_deactivate_object(obj_bone)
instance_deactivate_object(obj_bone_idle)


instance_activate_region(view_xview[0]-256,view_yview[0]-256,view_wview[0]+576,view_hview[0]+576,true)

}
This is what im using, and it has massively improved my fps, just change the deactivation and the size of activate region based on your screen size
 

TheouAegis

Member
Either use instance_activate_all() and instance_deactivate_region() or use instance_deactivate_all() and instance_activate_region(). Test results were somewhat inconclusive, but the _object functions were slower according to some test results.
 
Top