• 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 Adding tiles entirely through code?

D

DongKnobber

Guest
I can't find any functions in the documentation where it allows you to get a specific tile within a tileset and add it to a tilemap. Suppose you have a tileset that is 128x128 and each tile is 64x64, so 3 tiles in total (since you cant use the 0,0 tile). How exactly would you add a specific tile from that tileset onto a tilemap; suppose I wanted the 0,1 tile from the tileset to be placed at the 5,5 cell position on the tilemap so that it appears in the room on the correct layer.

So in a room with only an instance layer and a background, where the controller object contains the following code:
Code:
layer_id = layer_create(-999); //create a new layer in the room at a depth
tilemap_id = layer_tilemap_create(layer_id,0,0,tileset,10,10); //then add a tilemap to that layer
not sure where to go from here
 
Last edited by a moderator:
D

DongKnobber

Guest
I figured it out, I had to use tile_set_index() to get the tile data with the function you linked.

For " tile_set_index(tiledata, index); "
the index I assume is just the (n)th tile in the tile set starting at 1 but I have no idea why the function ask for tiledata when it returns a new tiledata. I could put in any number it seems and the result would be the same.

Code:
layer_id = layer_create(-999);
tilemap_id = layer_tilemap_create(layer_id,0,0,tileset,10,10);
var tile_data = 0;
var tile_index = 3;
tilemap_set(tilemap_id,tile_set_index(tile_data,tile_index),0,0);
Also I have no idea how to go about this now. The new tile system is way too CPU intensive for depth ordering based on the y position. In GMS1 I could simply use tile_add() and have each individual tile have its own depth at -y. Now I have to create a new layer for every depth and it runs like garbage. I'm getting about 30 fps in a room with 48 different layers and 2304 (48 x 48) tiles whereas in GMS1 I was getting over a 1000 fps with even more tiles.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
OKay, if all you are doing is setting the tile index with no transforms, you don't need the tile_set_index call... simply use the index value you need, eg:

Code:
tilemap_set(tilemap_id, 3, 0, 0);
As for the depth sorting, not sure how you'd best achieve this... Are you creating and populating the layers with tiles all in the create event? Layers should be pretty fast if all you are doing is rendering them, but changing 48 layers every step would be an issue.
 
D

DongKnobber

Guest
I have a large room where tiles are only drawn around the player so it could allow for a very large tile based game, in gms1 I slowly deleted tiles that not in the view once per step and added them in the direction that the player was going because having the room filled with tiles would cause the fps to drop near zero. The tiles also act as walls in which the player will be drawn under if the depth is lower than the tile. The player object has "depth = -y" in its step event and another issue in gms2 is when if the depth is equal to the layer that also contains tiles then the entire layer will start flashing even if the player is not even intersecting with the tile that is drawn at that layer.

But anyway I just scrapped that and now I'm just drawing all the sprites in order at the same layer.
https://forum.yoyogames.com/index.p...rity-list-nested-list-grid-binary-list.13425/
 
Last edited by a moderator:
Top