• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Optimise object and tile

NazGhuL

NazTaiL
Since the very first day I step into GM, I read about: Use object as wall vs use tile as wall.
If you choose to use object then running a scripts like @Nocturne Optimise object help you gain some fps.
Is it something we should consider again? Invisible wall under tiles or just tiles?

Also, the new layer functions and tilemap...How am I suppose to delete a single tile in the room?
What replace tile_layer_find, if != -1 tile_delete ?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You can use the tilemap functions for collisions if you wish, or stick o doing it the usual way with invisible walls and tiles on top. The tilemap functions are a little bit tricky, but (iirc) something like this should work:

Code:
var lay_id = layer_get_id("Tiles_Walls");
var map_id = layer_tilemap_get_id(lay_id);
var _x = tilemap_get_cell_x_at_pixel(map_id, mouse_x);
var _y = tilemap_get_cell_x_at_pixel(map_id, mouse_y);
tiledata = tilemap_get(map_id, _x, _y);
var tile = tile_get_index(tiledata);
if tile != 0
{
// collision!
}
Obviously, you can store the layer and tilemap IDs in a create event or whatever to speed things up...

As for deleting a tile, you don't really... you set the tiledata index to 0, which is always the "empty" tile (top left of the tile sprite). So:

Code:
var _x = tilemap_get_cell_x_at_pixel(map_id, mouse_x);
var _y = tilemap_get_cell_x_at_pixel(map_id, mouse_y);
var tiledata = tilemap_get(map_id, _x, _y);
tiledata = tile_set_index(0);
tilemap_set(map_id, tiledata, _x, _y);
I've not used these much myself, but I think that's how it works. :)
 
Last edited:

NazGhuL

NazTaiL
Ah thats why the invisible tile. Ok I get it.

In the manual, tile_get_index example:

Code:
var lay_id = layer_get_id("Tiles_sky");
var map_id = layer_tilemap_get_id(lay_id);
var mx = tilemap_get_x_at_pixel(map_id, mouse_x);
var my = tilemap_get_y_at_pixel(map_id, mouse_y);
var data = tilemap_get(map_id, mx, my);
var ind = tile_get_index(data);
data = tile_set_index(data, irandom(23));
tilemap_set(map_id, data, mx, my);
but tilemap_get_x_at_pixel and tilemap_get_y_at_pixel is not a valid function.

Thx.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Yep the manual is wrong, sadly. I documented the functions and then they were changed... Next update to the beta fixes it. The code I posted above should be correct though.
 

NazGhuL

NazTaiL
So, for anyone who needs to 'delete' a tile(set its index to 0) on mouse click:

Code:
if(mouse_check_button_pressed(mb_left))
{
var lay_id = layer_get_id("Tiles_1");
var map_id = layer_tilemap_get_id(lay_id);
var _x = tilemap_get_cell_x_at_pixel(map_id, mouse_x, mouse_y);
var _y = tilemap_get_cell_y_at_pixel(map_id, mouse_x, mouse_y);
var tiledata = tilemap_get(map_id, _x, _y);
tiledata = tile_set_index(tiledata, 0);
tilemap_set(map_id, tiledata, _x, _y);
}
A little more work than what we used to do but eh!, that's progress!
 

Mike

nobody important
GMC Elder
to wipe a tile...

tid = layer_tilemap_get_id("Tiles_1");
tilemap_set_at_pixel(tid, 0, mouse_x,mouse_y);

untested - no manual here, but this is pretty much all you need to do... Once I get near a PC, I'll check the code properly :)
 

NazGhuL

NazTaiL
to wipe a tile...

tid = layer_tilemap_get_id("Tiles_1");
tilemap_set_at_pixel(tid, 0, mouse_x,mouse_y);

untested - no manual here, but this is pretty much all you need to do... Once I get near a PC, I'll check the code properly :)
Works like a charm.

-edit-
And doesn't throw error if you click on a 'empty' cell.
:D
 

Mike

nobody important
GMC Elder
cool - I'd also recommend you store the tilemap id in the create event, then it's a one line thing :)

Tile maps are just a grid of INTs... some parts of the ints are flags, but its just an int.
 
Top