1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 Mirrior,Flip, Rotate All Tiles in Tilemap in Code

Discussion in 'Programming' started by 2d_warrior, Jul 23, 2019.

  1. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    201
    Say I want to be able mirrior, flip, and rotate all the tiles in a tilemap (in game not in room editor). Also to be able to do one, some, or all of these operations, and turn all these off too. What's the best way to do this?
     
  2. Arashi

    Arashi Member

    Joined:
    Feb 6, 2017
    Posts:
    143
  3. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    201
    Ok after trying this below I have questions.

    Event: Key Press ( Any Key)

    var lay_id = layer_get_id("Tiles_sky");
    var map_id = layer_tilemap_get_id(lay_id);
    var mask = tile_mirror | tile_flip | tile_rotate | 255;
    tilemap_set_mask(map_id, mask);

    It doesn't seem to do anything when I run it (even when altering the values between the ands), is there some setup stuff other than having a tilemap with that name in the room and having this code in an object in the room in a key press event, and pressing the key to test it?

    Secondly how would I change this line for the cases below it?

    var mask = tile_mirror | tile_flip | tile_rotate | 255;

    Would you write setting them all in a direction like this, or some other way?

    new_mask = 1 | 1 | 1 | 255

    Would reversing work like this?

    new_mask = !tile_mirror | !tile_flip | !tile_rotate | 255;

    What values do the places where tile_mirrior, tile_flip, and tile_rotate are actually take?
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,026
    You don't mirror, flip, rotate the tiles in the tile map, you do that to the tiles in the room. The tile map is just a palette of colors, except each color is a complete tile. tilemap_set_mask is for setting the mask, which is used for separating the index of a tile in the room from the properties of that tile.
     
  5. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    201
    So Arashi was incorrect for pointing me there? If so, then I take it tile_get_rotate(tiledata, rotate), tile_set_rotate(tiledata ect rotate), and the like for mirroring, and flipping is code I should use. How does one do that with more than one property at a time on each tile? In the example given in the manual below it only sets one tile's rotation, what if I want to set the entire tilemap/tile layer and multiple properties of each tile? I guess going through it like a 2d array would work, but the multiple tile properties is where I'm confused about what to do.

    Manual example

    var lay_id = layer_get_id("Tiles_sky");
    var map_id = layer_tilemap_get_id(lay_id);
    var mx = tilemap_get_cell_x_at_pixel(map_id, mouse_x, mouse_y);
    var my = tilemap_get_cell_y_at_pixel(map_id, mouse_x, mouse_y);
    var data = tilemap_get(map_id, mx, my);
    var bool = !tile_get_rotate(data);
    data = tile_set_rotate(data, bool);
    tilemap_set(map_id, data, mx, my);

    Starting at the last 3 lines, do I need to copy them like below if I want to change multiple tile properties of one tile at once. Setting the values and tilemap 3 times for each tile seems expensive for doing the entire tilemap, but is this how I should do it for each tile?

    var bool = !tile_get_rotate(data);
    data = tile_set_rotate(data, bool);
    tilemap_set(map_id, data, mx, my);

    var bool = !tile_get_mirror(data);
    data = tile_set_mirror(data, bool);
    tilemap_set(map_id, data, mx, my);

    var bool = !tile_get_flip(data);
    data = tile_set_flip(data, bool);
    tilemap_set(map_id, data, mx, my);

    Lastly should I check if a tile is already set to the rotation, mirroring, flipping values (when not negating them based on their actual values) before doing tilemap_set, or will adding such a check waste cpu cycles?
     
    Last edited: Jul 24, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice