Is there a performance difference between these two actions?

Just started using Construct 2? Post your questions here

Post » Sun Oct 18, 2015 1:00 pm

Hi,

I would like to know if there is a performance difference between using (create/destroy) and (set visible/set invisible)? Or doesn't matter wich method i choose to show/hide objects inside a layout?

Sometimes set invisible is not adequate because even if the object is invisible it still interact with others objects, like collision and buttons sprites, which still clickable. In this case destroy appears to be more usefull.

In some other cases destroy is not adequate and set invisible is the better option.

So, i think it depends on the use you gonna give to objects, isn't it? But in relation to performance, how it works?
B
14
S
5
Posts: 110
Reputation: 1,338

Post » Mon Oct 19, 2015 5:43 am

I'd imagine it would be faster to change an object's visibility, rather than creating/destroying it.

In both cases the object wouldn't be drawn, so rendering performance would be the same.
If the object isn't destroyed it's still available for interaction though.

Both have their uses, and it shouldn't be an issue of which is faster, instead just what makes sense in that situation. Usually I make invisible stuff that I'll either make visible again or just use for interaction. Whereas I destroy what is no longer needed.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Mon Oct 19, 2015 12:24 pm

If you are only managing small numbers of objects, this blog post applies: https://www.scirra.com/blog/83/optimisation-dont-waste-your-time

For large numbers of objects, creating and destroying objects is actually relatively CPU-intensive: the engine has a lot of internal data structures relating to created instances which all need to be updated when objects are created and destroyed. It's not slow per-instance, but adds up to a lot of work if you are handling hundreds of objects. In this case setting invisible (or repositioning far away) can be faster, but then you have to balance that with the fact they still exist and events will therefore still test against them. Repositioning far away is good with collision cells since it removes them as candidates for collision tests. Overall I'd say if you have a very large number of objects that are constantly appearing and disappearing very quickly, implement it by repositioning them far away instead of destroying. Otherwise normal create/destroy should be fine.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,684

Post » Mon Oct 19, 2015 2:38 pm

R0J0hound and Ashley,

I'm honored! Thank you very much for this! I will use both, according to the situation. I don't have a lot of objets, but i was trying to optimize performance, so that was a concern...but not anymore. Thank you again for clarifying things for me!

Best regards!
B
14
S
5
Posts: 110
Reputation: 1,338


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest