Is it better to destroy objects that are not needed temp?.

0 favourites
  • 9 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hey all,

    I was wondering if it is better to destroy objects that are not needed temporarily and spawn them when needed, or better to move them away from screen?

    I was thinking of reducing the object count at any given time during game play and was wondering if it helps to keep it at a minimum or will it not make a difference. Will the device end up using more resources to create objects than rendering them off screen?.

  • Its always a good idea to clean up objects that are not needed, so in that regard I would suggest doing that. However if you only have a few objects in your game, I doubt you will notice any improvement.

    How many objects are you talking about? and have you tried to use the debugger to get an estimate of how many resources your game is using?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • At first i had about 45 sprites, then i transferred some sprites as an animation frame to another sprite and deleted them, that brought it down to about 35, then i did the create when needed and delete otherwise stuff and that made it come down to 29 min and 31 max sprites at any given time.

    I use about 12 physics based objects, and i guess that takes up most of the resources. Imagine a ball(physics for bounce, twist etc) popping into the screen , i have setup parameters for the ball to disable and enable physics collisions at certain places in the layout. When the collisions get enabled, the collision check count shoots up, so i was wondering if reducing the number of objects (that are off screen) will reduce the collision count. Thing is the collision check count are extremely varied and i can't tell if it helped at all during debugging.

    I get about 60 fps on mobile but it reduces slightly when the collision checks happen, i was wondering if creating objects would take up more resources for a mobile device.

  • they dont take up more resources on mobile, mobile has less resources.

    • collision is one of the most performance killer tings in game development.
    • even your objects are at offscreen game have to check for their collisions.

    compleately removing your objects would make a good change. u can rather turn their collisions on or off too.

    this would help you alot:

    https://www.scirra.com/tutorials/925/mo ... ance-boost

  • I get about 60 fps on mobile but it reduces slightly when the collision checks happen, i was wondering if creating objects would take up more resources for a mobile device.

    As stated collision checking can be rough, be sure to use "is Overlapping" rather than "On collision" if you don't already it requires less resources.

  • As stated collision checking can be rough, be sure to use "is Overlapping" rather than "On collision" if you don't already it requires less resources.

    What is the real difference with overlaping and collision? and how comes overlapping uses less resources? Are they using different algorithms? or only about collision plygones?

  • [quote:svzk0u2n]What is the real difference with overlaping and collision? and how comes overlapping uses less resources? Are they using different algorithms? or only about collision plygones?

    I don't think there are any difference in the code. If you look at this example:

    If you compare the basic "On collision" with "Is overlapping" you get the same amount of collisions. However if you modify the "Is overlapping" and it has to be done exactly like this, with a For each and the distance check as second condition you can reduce the amount of collisions which makes it more effective. You cant do that with the "On collision" it will check all objects on the map constantly.

  • nimos100 i get your point now.

    btw

    Pandy to increase the game perfomrance furter u may want to know this:

    here is a very basic collision algorithm for rectangle sprites:

    if (
    	item01.x + item01.width > item02.x && 
    	item01.x < item02.x + item02.width && 
    	item01.y + item01.height > item02.y && 
    	item01.y < item02.y + item02.height
    	){
    	return true;	
    } else {
    	return false; 
    }[/code:28b14lvm]
    imagine how it is for polygones. Construct 2 automatically draw collision polygones for your sprites by looking at their transparent area when you import them.
    
    you can view that polygon when you double click your sprite and press the last button on left menu on sprite editing screen.
    If you can alter this polygones to achieve best resault with least points it would greately increase your performance too
  • Thanks for the help guys,

    Aleq I mostly have a ball bat collision thing happening, i've got the bat to a basic rectangle, tho i want the ball's physics to be exact, so i guess i need the balls's polygon to be as it is with it's multiple points

    nimos100 I tried out replacing my on collision events with overlapping and loops such as your example, tho it's not triggering the variables that used to trigger on collision events, i'll try it out again later and get back.

    Thanks again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)