• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Best way to remove tiles at given region?

F

Facet

Guest
Hello

I'm working on dynamic tile loading system and I'm looking for best and fastest way to remove tiles on specific region like a:

tiles remove all x, y, x+100, y+100 (maybe with given depth, but best for me is to remove all tiles no matter depth in given region)

I know, I can get tile x,y etc, but all solutions I know need strong loops end overall are not good for fps, maybe I missed something. Any help appreciated! ++

Thank's
 
W

whale_cancer

Guest
Depends on exact implementation. Why are you removing them? Are they predefined regions (for example, black tiles to cover a hidden area)?

Assuming by...
Code:
tiles remove all x, y, x+100, y+100
...you mean just the tiles in a 100 x 100 pixel area, well, that shouldn't hit your FPS if you just use nested for loops.
 
F

Facet

Guest
oh, yes, bad example, small value :) Let's say:
Code:
tiles remove all(x, y, x+2048, y+2048)
and I can have dozens or better tiles here, I'm creating it by code only so I have to remove it by code too. I'm removing, because this is some king of open world engine, no problem with objects, it working as should and fast, just I'm looking for some tips with tiles.
 
J

Jaqueta

Guest
Use a for loop to remove the tiles in the given positions
I recommend rounding the values according to the grid size
I'm actually creating a script right now.
 
W

whale_cancer

Guest
and I can have dozens or better tiles here
Dozens is not a lot of tiles. Are you removing them as a sort of chunk system? Have you done tests with nested for loops and observed FPS drops? I have a tile system as well and I find tiles to be extremely lightweight when it comes to impact on systems. If it is not clear what I mean by nested for loops, a script using this system would look something like...
Code:
for (w = 0; w < argument0/16; w += 1)
{
    for (h = 0; h <  argument1/16; h += 1)
    {
        tile_layer_delete_at(1000000, w * tileSize, h * tileSize);
    }   
}
As for depth, unless you are doing something more complex, there is usually not much of a reason to stray from the default of 1000000. If you have something like a tile that is overtop of everything else, just use a single depth value for those and add another tile_layer_delete_at for that layer depth.
 
F

Facet

Guest
Use a for loop to remove the tiles in the given positions
I recommend rounding the values according to the grid size
I'm actually creating a script right now.
Rounding is good idea of course, but I have very different x,y and I can't round it. Maybe I have to create tiles different way. I'm using it rather as some kind of background not tiled tiles :D and x,y can be very random.

Maybe here other solutions is need not tiles based. Let me explain. I have tree created, and this must be object for some reason (really). Under tree I need background, so I'm creating here single tile for now. Maybe best would be create sprite instead of tile, but I see same problems here with delete system.

With at_depth I still need x,y

Maybe here is some solution with surfaces? I don't know :p
 
A

anomalous

Guest
I wrote two large world tile placer/removers, the second one which just uses tile add/delete, works fast.
The trick to making it fast has to do with how you organize your code, loops, and data structures in this case. The functions are what they are.

I store all tile data in a grid, which includes background, top, left, and depth parameters. The top/left components are the exact inputs to tile_add/delete, you don't want calculations where you can help it, since the loop is the killer.

I would suggest making a macro for your tile size, and call it "ts" or something very short. I also did half-tile size "hts" , another one you may want to go ahead and make.
This way your code will not have to use a variable for the tile size (its slower) but if you did a fork of your game with a new tile size, you could just change the macro and done.
 
F

Facet

Guest
Thank you both for tips. I think I will reorganize tile spawning for some more grid based. I need tree and other objects random on map, but it can be random based on some grid 32, 64 or like this. Then I can use loops easy and with no cpu wasting.

Other matter, I want to save some graphic on very random locations, like a blood, footprints (just example) but I think it should be done as object moved to surfaces. Just thinking. Anyway, any other suggestions welcome :D

I know, even if here would be ready game maker function, like a
tiles remove all(x, y, x+2048, y+2048) it will be still loop and same result, so not so much benefit, I can create function like this too.

Well, I'm using right way I think now :) But all tips are very handy for other works with tiles, and thank you.

I have tile creator object as I said, so when it is destroyed/saved, I can easy destroy it's tile too of course, so I just add:
Code:
tile_layer_delete_at(depth+2, x-128, y-128);
because I always create this tile at this position:
Code:
 tile_add(bck_tree, 0, 0, 256, 256, x-128, y-128, depth+2);
I have object stored in map, so I not need other maps for tiles. I think this is best and simplest way. I will use loops for other tiles, grid based of course too, just they are different a little.
 
Last edited by a moderator:
A

anomalous

Guest
So far I use particles for non-collision decals (like footsteps), and objects for collision decals (like a fire field)
The only downside to particles (aside from no collision) is that they are a PITA to set up. Once set up though, they are easy to use, and using part_particles_create, they are fire and forget (mostly).
I was unable to envision anything better using surfaces, perhaps someone has a better way.
 
Top