destroying 1000 objects using more cpu than creating 1000 object. slowing game. Solution please.

0 favourites
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hi Friends,

    I am creating a racing track which needs object to be created every tick so more than 1000 objects are created within 20 seconds. CPU is 12%. Now to reduce burden I destroy each object after 5 seconds. But when destroy action happens cpu reaches 35%. So when I don't destroy any object, game slows down after 15 seconds but if I keep destroying objects to free memory then game slows down within first 5 seconds. I feel construct 2 is having a bug that it is not releasing memory on destroying object. Can anyone help me how to decrease cpu consumption by destroying objects?

    Regards,

  • One reason it might cause your cpu to spike when you destroy items/objects, is cause the coding you have to calculate the position of the 1000 objects are taking in consideration the position of objects at all time... if you change that and only use the position of all objects as being important when they spawn and then never compare their position while the game runs, when gets destroyed they shouldn't use that cpu spike anymore.

    Also it might be based on how many items are you destroying in 1 tick... maybe limit them instead of each 5 seconds, more to when each individual object reaches outside of screen ? and apply the removal for each object and not all objects? just an idea.

    This might be a event coding issue more then cpu dump data speed.

  • I tried to reproduce this using fade out to destroy the objects. Enabling fade always leads to a lower CPU usage (using C2 261 64-bit).

  • I tried to reproduce this using fade out to destroy the objects. Enabling fade always leads to a lower CPU usage (using C2 261 64-bit).

    thanks for trying. I followed your solution but no luck, cpu consumption is still same. high consumption. Me too using same version of construct 2.

  • One reason it might cause your cpu to spike when you destroy items/objects, is cause the coding you have to calculate the position of the 1000 objects are taking in consideration the position of objects at all time... if you change that and only use the position of all objects as being important when they spawn and then never compare their position while the game runs, when gets destroyed they shouldn't use that cpu spike anymore.

    Also it might be based on how many items are you destroying in 1 tick... maybe limit them instead of each 5 seconds, more to when each individual object reaches outside of screen ? and apply the removal for each object and not all objects? just an idea.

    This might be a event coding issue more then cpu dump data speed.

    THanks for giving time to my issue. to reduce cpu consumption I am not using distance calculation. out of many alternative I am currently keeping a sprite at bottom of screen and when objects touch that destroy the object thus saving mathematical calculation. Also, I have always noticed that games built on other platform do not consume this much cpu as construct 2 does. C3 also has same issues even c3runtime is not much improvment in real world may be on papers. Though I understand it is still in development. I love construct 2 and think Ashley should look into this.

    Any other solution is most welcome would love to try.

  • What are you using to preview your project? Using the newest version of chrome or NW.js is significant faster then the newest version of firefox. Did you try the same thing in an empty, new project to make sure that creating/destroying is the cause? Maybe sharing your project can help us to find a solution.

  • What are you using to preview your project? Using the newest version of chrome or NW.js is significant faster then the newest version of firefox. Did you try the same thing in an empty, new project to make sure that creating/destroying is the cause? Maybe sharing your project can help us to find a solution.

    I tried debugging using chrome. I have to run it on android and on mobile performance is too bad to even play this game for 15 seconds. Sample capx I will try to send here. Functionality shown in sample is just small part of my game.

    touch.affle.com/explorations/mohan/capx/sample.capx

  • Using two effects on so many sprites is really a bad idea, especially for a mobila game. Try to optimize the image so it can be used without any effect. You dont need to includ dt in bullet behavior because it is already using it. From your example i dont realy get how your game will work, but i am sure there will be some things that need improvement. Here's an example where I think it could work better:

    1drv.ms/u/s!Ap_-qxoGKbDcg2-8y22xY2n9jbyh

  • Applying effects to the layer will probably be much better here, so just remove them from the road object and add them to the road layer.

  • Using two effects on so many sprites is really a bad idea, especially for a mobila game. Try to optimize the image so it can be used without any effect. You dont need to includ dt in bullet behavior because it is already using it. From your example i dont realy get how your game will work, but i am sure there will be some things that need improvement. Here's an example where I think it could work better:

    https://1drv.ms/u/s!Ap_-qxoGKbDcg2-8y22xY2n9jbyh

    What my game is doing? Here is preview of my game. youtu.be/tcgMAigbFdg You can see road is created with bending dynamic angles, Also video is created when I was using least effects (2 weeks back). Within few seconds u can see slow down and that cpu consumption is still there. Main problem is destroying process eating cpu.

  • Applying effects to the layer will probably be much better here, so just remove them from the road object and add them to the road layer.

    THanks for the reply. Removing an effect from object is not affecting much though a little. Main issue here if I don't destroy road object cpu consumption is less but if I start destroying road object to save memory, then cpu spikes up. I think destroying is not releasing memory. You can try it with any self example and I assume lets Ashley make aware of this issue though is already working hard on C3. Nice man.

    Any alternate solution will be helpful too. Though I tried fadeout solution too which couldn't help me.

  • Did you look at my example? Using a 'for each' loop does not make things better. Use the 'wait' property of the fade behavior. It works a little faster then comparing the Y coordinate to destroy the road.

  • Did you look at my example? Using a 'for each' loop does not make things better. Use the 'wait' property of the fade behavior. It works a little faster then comparing the Y coordinate to destroy the road.

    Hi Kriand,

    I checked your sample, thanks for sharing it. I noticed that your capx is consuming more cpu than my sample capx within first 15 seconds. You can cross check it in debug console. So that method didn't work. But appreciating your effort to look into issue. Still looking for more solution.

  • I can not confirm that. Both examples start with about 15% CPU usage on my PC and my example keeps this value, even though the first sprites start to fade. For the fact that tons of sprites are created, I find this utilization quite normal.

    I can imagine two options. First: I replaced the sprite with a TiledBackground and was able to reach a constant CPU usage of about 8% instead of 15%.

    The second possibility is the prefabricate and assembling of road parts with sprite frames or animations. It need a little more programming, but would run much smoother. Since it should be a mobile game, this method should be seriously considered.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have you not tried particles yet?

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