Tile-Game Water Physics

0 favourites
  • 12 posts
From the Asset Store
Water Sound consists of 85 seamless loops of water sounds and 5 Thunder sounds.
  • Hi! Okay, so I made physics to allow water to flow in my tile digging game. The problem, is it's REALLY laggy. It checks the entire 325x125 array every few seconds, and of course that hurts the performance.

    So, my question is, is there a better way to do it? Is there a way to make it so it doesn't lag?

    This is what I currently have:

    <img src="https://dl.dropboxusercontent.com/u/61808535/scirra.png" border="0" />

    Thanks in advance!

  • it's not entirely clear what you're doing, so it could be a number of things.

    Although OR blocks have been changed quite a bit recently, sometimes being slow or not triggering properly. I've stopped using them for the time being.. it wouldn't hurt to see if that's what causing it.

    if there's a lot of actions that I don't want to be duplicated you can put them in a function, or just do this in place of the OR block:

    +local var: OR = 0

    +condition 1:   >set OR to 1

    +condition 2:   >set OR to 1

    +OR = 1        >actions

  • keepee Seems like a good way to replace the OR blocks, i'll try it.

    Also, what i'm trying to do is that if a water tile is next to an empty tile or a certain tile, it'll change it to a water tile. I thought it might be the large array being checked but it could also be the OR blocks, i'll give it a go.

  • Okay, it seems to have worked, just some small lag spikes here and there, Thanks!

  • Well the problem is back, and it doesn't seem to be the OR blocks. I was able to pinpoint the problem to the reading of the large array. Is there any way I can reduce the lag from this? Because every time it goes through the array, the FPS goes from 50 to 18.

  • Instead of looping over the entire array maybe you could loop over only part of it at a time? Another idea would to reduce the number of times you read array positions by saving the values of the adjacent cells to variables.

  • R0J0hound How would you be able to loop over only part of an array?

  • As a simple case instead of doing this.

    Array: for each xy
    --- do stuff

    You can instead do your event like this for the same effect. Except you would have to use loopindex("x") and loopindex("y") instead of Array.CurX and Array.CurY.

    System: for "x" from 0 to 325-1
    System: for "y" from 0 to 125-1
    --- do stuff

    Now it can be time consuming to loop over each cell as might be your case since it has elaborate logic that is run per cell. But if you do half the array one frame and the other half the next you can reduce the stall by half.

    One such implementation would be:

    Global number distribute=0
    
    Every tick:
    --- add 1 to distribute
    
    System: distribute = 1
    System: for "x" from 0 to 325-1
    System: for "y" from 0 to 62
    --- do stuff
    
    System: distribute = 2
    System: for "x" from 0 to 325-1
    System: for "y" from 63 to 125-1
    --- do stuff
    
    System: distribute = 2
    --- set distribute to 0

    Alternately you could do every other column with something like this:

    Global number distribute=0
    
    Array: for each xy
    System: compare Array.CurY%2 = distribute
    --- do stuff
    
    Every tick:
    --- set distribute to (distribute+1)%2
  • R0J0hound

    Okay so I did this:

    <img src="https://dl.dropboxusercontent.com/u/61808535/Eventsscreen1.png" border="0" />

    and I think it works, but the FPS has dropped to 13-19. Am I doing something wrong? Thanks fr the help!

  • R0J0hound So, in event 3, I changed wait 0.1 to wait 0, and it became that the FPS is 60 but drops to 25 every 2 seconds. Er, what do I do? Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hard to say if the idea is implemented right from a picture but it looks somewhat on par. You can extend the idea future by perhaps instead of looping through half of the array at a time, loop through a fourth or tenth.

    Another idea is to not call updatetile every time. I don't know what it's doing exactly but it probably is a main fps eater if it creates new tiles or does something with all the tiles.

  • R0J0hound Well for the large array basically I have tiles onscreen, and when they scroll off-screen, they go to the other side, and update. Update tile is the function that is called that updates their animation frame. In the debugger, it is second to using CPU. First is the water.

    Also, I made it go through the array in quarters, but it seems to get WORSE rather than better.

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