How do I count tiles without killing the CPU?

0 favourites
  • 8 posts
From the Asset Store
In this template the music plays without looping in your game
  • Hello! Let me explain the game I am making and the problem.

    The Game:

    You are a roomba collecting dust from the floor.

    Months ago I used a technique that allowed the roomba to collect dust. The problem was that the dust collection was an extensive hierarchy of objects, which slowed the initial calculation when you boot the game up.

    A couple of days ago I have finally changed to tiles. I can draw whatever I want on the floopr and the roomba can delete these tiles by passing by in-game with no issue.

    Everything works as intended and the game doesn't suffer from the slow calculation.

    The problem:

    I want that the progress of collecting dust is expressed through a bar in the HUD.

    The more you collect, the more the bar gets bigger, until it's done.

    At the moment, the only thing I have thought of was to count the number of tiles in the game and subtract once the roomba collides with them.

    I have followed this Construct 2 tutorial, which worked for Construct 3 as well.

    construct.net/en/tutorials/working-tiles-tilemap-count-1427

    The problem is that the game now takes a lot of calculation for counting the tiles since they are 1 pixel each. A small square full of dust may contain 72677 tiles, for example.

    My questions are:

    1) Is there a better way to count tiles or make the counting faster?

    2) If not, do you know a better way to make a progression bar for the collected dust?

    3) If not, and if you think this technique is not necessary or ugly, do you know a better way to make dust in-game without freezing the game?

    Thank you so much... Have a good day!

  • store tiles as x-y positions in a dictionary, use key.count as progression bar

  • 72677 for just a small area sounds like an amount that will very likely lead to performance problems, I would suggest changing the game design to allow for larger dust particles.

  • 72677 for just a small area sounds like an amount that will very likely lead to performance problems, I would suggest changing the game design to allow for larger dust particles.

    I have tried different types of dust types.

    There is another type of dust that the roomba collects, which uses particles. But the purpose of that type of dust is completely different and is visually speaking different for a motive. Let's call it "special dust" just for reference.

    Using the same technique for normal dust isn't ideal and doesn't fit well with a vacuum cleaner. This is why using tilemaps works incredibly well. It's as if the roomba is a rubber on a sheet full of scratches. Unfortunately, the tiles are tiny, and therefore for each counted tile you get big numbers like 72677.

    I have tried with bigger tiles and sadly they don't fit well with the rest of the game, aesthetic-wise.

    At this point, I'm going to either find another way to make normal dust or just decide to see if there is another way to not calculate all the tiles (I don't know how, but we'll see).

    store tiles as x-y positions in a dictionary, use key.count as progression bar

    Yes, I'll let you know if it works!

  • to count tiles:

    little example of a vacuum mechanic, probably not really what you are trying to do though:

    https://drive.google.com/file/d/1DFmATBH-gtIYrIbpnbeOIWqNO36mWEAA/view?usp=sharing

  • You may get better performance with a canvas instead of tilemap.

    Even with a tilemap with 1x1 tiles its slow even just erasing.

    dropbox.com/s/0jkp71pl9nvyw08/roomba_tilemap.capx

    An alternate idea is to grab a screenshot and use some JavaScript to scan the image for set pixels. It works, but it needs to flicker as I need to hide the other layers for a frame.

    dropbox.com/s/il3xbkj19f8n78n/roomba_screenshot.capx

    So here's the example using the C3 canvas. It works well for erasing but loops in events are slow, so here it does the scan of the pixels over multiple frames. Seems to work well, but if you resize the game window in any way the canvas will clear. May need some more logic to periodically save the canvas and reload it as needed.

    dropbox.com/s/ki35vb1bx2xztuf/roomba_canvas.c3p

    If you have the full version of c3 you could also handle the canvas pixel scanning in javaScript as that would be much faster.

  • Throwing some ideas out here - instead of counting tiles, generate the dust dynamically and simply keep track of how much was created in the first place.

    Or set up a loading screen style transition when running the counting event, if it's only a one time thing.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok time to answer all of you

    to count tiles:

    little example of a vacuum mechanic, probably not really what you are trying to do though:

    https://drive.google.com/file/d/1DFmATBH-gtIYrIbpnbeOIWqNO36mWEAA/view?usp=sharing

    fedca

    Thanks for the counting tiles!

    As for your demo on google, this was actually my previous gameplay for obtaining dust.

    I still have this style saved on my project, easily togglable, 100% functional and it does its job.

    The motive I decided to try another way is because I wanted to have more freedom on the type of dirtiness coming from the dust. I was hoping I could do that, but if this tiling issue gets harder for me to produce, it's fine - I'll go back to that.

    After all, from 72677 tiles to 82 pieces of dust, the difference is noticeable.

    Plus, I don't have to make a dictionary for counting the pieces of dust in this way.

    ... Yeah, maybe this is the most convenient idea... I'll think about it for my project, but in any case, I want to see if there is some way to produce the effect I'm asking for in this topic.

    In the meanwhile, thank you so much for reading and answering this topic!

    You may get better performance with a canvas instead of tilemap.

    Even with a tilemap with 1x1 tiles its slow even just erasing.

    dropbox.com/s/0jkp71pl9nvyw08/roomba_tilemap.capx

    An alternate idea is to grab a screenshot and use some JavaScript to scan the image for set pixels. It works, but it needs to flicker as I need to hide the other layers for a frame.

    dropbox.com/s/il3xbkj19f8n78n/roomba_screenshot.capx

    So here's the example using the C3 canvas. It works well for erasing but loops in events are slow, so here it does the scan of the pixels over multiple frames. Seems to work well, but if you resize the game window in any way the canvas will clear. May need some more logic to periodically save the canvas and reload it as needed.

    dropbox.com/s/ki35vb1bx2xztuf/roomba_canvas.c3p

    If you have the full version of c3 you could also handle the canvas pixel scanning in javaScript as that would be much faster.

    R0J0hound

    Thank you so much for your demos! I appreciate your help! I admit I have never used the drawing canvas and by judging the difference I believe it's the one working better.

    Deleting 1x1 tiles in-game doesn't affect the performance unless you're always counting (just as proved in your first demo). In fact, the whole idea of using this feature would work if it wasn't for the progression bar.

    Yeah I own the full version of C3 alright, I'm not the best at javascript but I bet it can do better.

    As I mentioned before with fedca, I'll keep in consideration all the help to make a resolution for this feature.

    Throwing some ideas out here - instead of counting tiles, generate the dust dynamically and simply keep track of how much was created in the first place.

    Or set up a loading screen style transition when running the counting event, if it's only a one-time thing.

    oosyrag

    Thank you for your ideas! Yes, as I mentioned before, I do have a similar technique in my game, which is currently suspended to try a new, (possibly) better way to collect dust. This feature is similar to the demo provided by fedca.

    In the game, I have also tried to add random dust across the map, in different sizes and shapes. Of course, the more you add, the worse it gets with the performance. After 5000 pieces of dust, you see a downgrade. Luckily you don't need to go for 3000 pieces, just the ones you need, which usually go from 80 to max 500 depending on how to use them.

    As I said to fedca, I was trying to see if I could make the roomba more of a rubber erasing scratches. While this works in-game, it doesn't go well when it's about data and calculations. Since I'm a sort of a newbie, I'm open to all ideas but at the same time keep acknowledging that some of these can't be made at the moment. So yeah, it's highly probable that I'm going back to the previous technique for getting dust since overall it works well.

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