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

Get help using Construct 2

Post » Fri May 02, 2014 6:40 am

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?.
B
16
S
4
Posts: 138
Reputation: 1,454

Post » Fri May 02, 2014 6:46 am

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?
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri May 02, 2014 7:02 am

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.
B
16
S
4
Posts: 138
Reputation: 1,454

Post » Fri May 02, 2014 7:16 am

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
Truth shall be your freedom...
B
14
S
2
G
1
Posts: 45
Reputation: 930

Post » Fri May 02, 2014 7:44 am

Pandy wrote: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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri May 02, 2014 7:53 am

nimos100 wrote: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?
Truth shall be your freedom...
B
14
S
2
G
1
Posts: 45
Reputation: 930

Post » Fri May 02, 2014 8:17 am

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:
Image

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri May 02, 2014 9:55 am

@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:
Code: Select all
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;
}

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
Truth shall be your freedom...
B
14
S
2
G
1
Posts: 45
Reputation: 930

Post » Fri May 02, 2014 12:40 pm

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.
B
16
S
4
Posts: 138
Reputation: 1,454


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests