Animating tilemaps during runtime

1 favourites
  • 5 posts
  • I want to animate tilemaps in my game at runtime to avoid creating more sprites (tiny ones at that) and cluttering my project by doing so. This also makes it easier to alter levels quickly.

    I've achieved this goal but the method is only effective when the tilemaps are relatively small (referring to the amount of tiles that are currently painted on the map in editor) because the function plugs in a parameter for the 1st and last tile UID in the animation and use nested For Loops for checking the entire tilemap every time the function is called. Since the animation frame have to change every x seconds this bogs down the device quite a bit. A bit being 30 FPS...

    I figured For Loops were probably a bad choice for something like this but I couldn't figure out any other way to do it so far.

    I think this would be WAY more effective if I could access the tilemap as a JSON then find the tile UID(s) I'm comparing in the function and then, if the conditions are met, use the replace expression to replace those UID(s) with itself +1.

    Here's a screenshot of my current event sheet.

    Does anyone know how I might do what is directly above this question or maybe something even more efficient?

    Thanks in advance!

  • I am not sure if replacing lots of numbers in a large JSON and then loading this JSON back into the tilemap will be any better for performance.

    I too have animated tilemaps in my project and I'm only updating the tiles which are inside the visible area, in my case this is about ~1000 tiles. Updating them every 0.16s only costs a couple of %% in CPU utilization.

    Let's say there are 5 animated tiles in the tilemap - from 10 to 14. After tile 14 the animation restarts from tile 10 again. Then the code can be something like this:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey that's awesome! Thanks! Always nice to hear from a legend such as yourself DOP ;)

    So I made the system MUCH better. Beforehand, I couldn't paint an entire level and also animate the same tilemap much because of the resources required to do so for that method. Now, the system can animate an ENTIRE level (trust me, I tried it - though the gif attached is not as an extensive test the results were the same. I'll explain why it's really here in a minute).

    At this point everything is smooth and as efficient as I could imagine anything like this being. However, I have an issue that's occurring in the left hand corner of the tilemap regardless of what I paint there. I think it's the 0,0 position (which 0 is somehow being stored in the array and thus picked as a position to animate) but I can't figure out how to eliminate this issue.

    Anyone have any ideas?

    imgur.com/a/NxUKl0F

  • I think it's the 0,0 position (which 0 is somehow being stored in the array and thus picked as a position to animate)

    Are you resetting the array size to 0 before filling it? Set width to 0, height and depth to 1.

  • I tried that as well before posting and it didn't have any effect. Thank you though!

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