• 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!
  • 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 layer_get_id() / layer_tile_create() bug?

I want to use tiles to add blood decals to the floor, but the tiles are not being created and I keep getting this in the output window

I'm using this code to place the tiles:
Code:
var n = layer_get_id("tiles");
layer_tile_create(n,x,y,tile_blood,1,1,16,16);
As you can see, I do have a tiles layer named "tiles" in the room.


I checked the manual to make sure I was using the functions right, but it seemed like it was okay.
Could this be a bug or is there something I'm still doing wrong?

EDIT: I just read about layer_tile_create() in the manual. It says I should never use it outside of compatibility scripts. Why is that? And if I can't use this function, how do I add tiles to a tile layer?
 
Last edited:
A

Ariak

Guest
@Nocturne
This is a bug in GMS2. `layer_get_id` of a tilelayer will return -1 (couldnt find any) if there is no Tileset assigned in the room editor. The bug has been reported.

As a result you will either have to create the layer + tilemap through code, OR set a tileset to the layer in the room editor.

The function you are looking for is called layer_tilemap_create - not layer_tile_create.

There are indeed undocumentend layer_tile functions, but these require a unique tile element id. These seem to be new functions where we can set the blend,alpha etc. of indivudal tiles and are probably part of a future update. EDIT: as nocturne pointed out i was wrong - they are for compatability scripts.
 
Last edited by a moderator:

Nocturne

Friendly Tyrant
Forum Staff
Admin
The functions the user is referring to are not "undocumented functions that will be part of a future update". They are undocumented functions that are only for internal use. http://docs2.yoyogames.com/index.html?page=source/_build/3_scripting/4_gml_reference/compatibility_functions.html

As for what the user says, I misread the full topic and they are missing a step... they need to get the tilemap layer that the tile is on, not just jump from the layer ID to the tile. You create a layer, then you create a tilemap and THEN you add/remove/change the tiles on the tilemap.

So:

Code:
var n = layer_get_id("tiles");
var m = layer_tilemap_get_id(n);
tilemap_set_at_pixel(m, TILE_INDEX_VALUE, x, y);
:)
 
Thanks for the help guys! I got the tiles to spawn, but they automatically snap to a 16x16 grid. Is there a way to create tiles at any point in the room instead of snapping to the grid?
 
Top