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
  • Instead of creating and destroying objects as they come and go, alter their visiblity and positions. It's far less taxing I believe, although in the end it depends on how many objects you actually need.

  • Reduces the cpu usage for some percent but not as much as i thought it would. Never the less its better then creating and destroying objects the whole time.

  • But why are you creating roads every tick?

    The straight parts of the road can be done with single stretched rectangle sprites, and the rounded turns can be done by putting a circle sprite at the turns. It ends up looking the same as in the video of your game anyway, plus only uses maybe 20 or so sprites at any given time.

    You shouldn't be generating road by time intervals anyway. Just add more as the end of the road gets too close to the top of the screen.

    Destroying the road should be as simple as just checking when the y is below the bottom of the screen and it's off screen.

    dropbox.com/s/8c3u8prum0sh63u/infinite_road_round_turning.capx

    At any rate this is how any similar games you've seen would do it.

    In the example the view is fixed and all the sprites are moved down. You can do the opposite, leave everything fixed and just scroll down. The only real change other than not moving the road would be to to reference the top and bottom in the view instead of using fixed y positions.

    So instead of y>-100 use y>viewtop-100

    and instead of y>480+100 use y>viewbottom+100

    I apologize if that's not the names of those expressions, but the actual one's should be similar.

  • Nice one as always R0J0hound. This should solve the performance issue.

    The only thing that needs to be added is to limit the angle of the road, like in my last .capx where the imagepoints x position is compared, or to adjust all objects when the road leads outside the layout on the X-axis:

    Can be made a little softer with lerp.

  • But why are you creating roads every tick?

    The straight parts of the road can be done with single stretched rectangle sprites, and the rounded turns can be done by putting a circle sprite at the turns. It ends up looking the same as in the video of your game anyway, plus only uses maybe 20 or so sprites at any given time.

    You shouldn't be generating road by time intervals anyway. Just add more as the end of the road gets too close to the top of the screen.

    Destroying the road should be as simple as just checking when the y is below the bottom of the screen and it's off screen.

    https://www.dropbox.com/s/8c3u8prum0sh63u/infinite_road_round_turning.capx?dl=1

    At any rate this is how any similar games you've seen would do it.

    In the example the view is fixed and all the sprites are moved down. You can do the opposite, leave everything fixed and just scroll down. The only real change other than not moving the road would be to to reference the top and bottom in the view instead of using fixed y positions.

    So instead of y>-100 use y>viewtop-100

    and instead of y>480+100 use y>viewbottom+100

    I apologize if that's not the names of those expressions, but the actual one's should be similar.

    RJ...always nice to hear from you and your solution is also very close to my requirement. Best part is less cpu consumption that makes a lot of difference. Also, as kriand stated it is going out of layout most of time I am facing the issue. His provided solution I couldn't implement, my bad not an expert of construct 2. One more problem is when I put some tiled background below it then it looks like road is floating above tiled bg and not at all real. Any solution for this?

    Also, apologies for couldn't replying early as I was so frustated with the issues in the zombie game that I left it for sometime and started developing other sniper shooting game. Output is really good. You can try it here and feedback is always welcome bit.ly/affleeq2

    Now I am back to zombie game. gonna work harder this time.

    Thanks :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Nice one as always R0J0hound. This should solve the performance issue.

    The only thing that needs to be added is to limit the angle of the road, like in my last .capx where the imagepoints x position is compared, or to adjust all objects when the road leads outside the layout on the X-axis:

    Can be made a little softer with lerp.

    Hi Kriand,

    Thanks a lot for looking into this issue and it has been big help. Also as u said with ROJ solution, road goes out of layout in X-axis and I tried your solution but it didn't work for me that much. I am sure I am not able to implement is correctly. Can you help in limiting the road inside game screen only. One more issue is the bg which is kept below road looks very fake as road is floating above it. How can I make it more realistic like road is created as part of some tiled background.

    Thanks again.

  • If the background is not monochrome you have to move it with the rest of the objects and reset its position like in the endless runner template. All other objects you spwan (trees, houses, monsters, powerups etc.) must be part of the same family as the road, so they move with it.

    1drv.ms/u/s!Ap_-qxoGKbDcg3UaOS8k-zX8PkvN

  • If the background is not monochrome you have to move it with the rest of the objects and reset its position like in the endless runner template. All other objects you spwan (trees, houses, monsters, powerups etc.) must be part of the same family as the road, so they move with it.

    https://1drv.ms/u/s!Ap_-qxoGKbDcg3UaOS8k-zX8PkvN

    OMG this is what I was looking for....thanks a ton. not have words to thank u man. U r brilliant. Gonna work now to finish it.

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