GMS 2 Tile Ids wrong when Flipped or Rotated, Is it a Bug?

Discussion in 'Programming' started by 2d_warrior, Jun 28, 2019.

  1. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    201
    So I'm working something to gather the tiles in a tilemap and copy them. Something strange, that may be a bug in GM Studio 2, happens to the tile ids when they are flipped, or rotated in the room editor. The tile ids become huge numbers. This makes reading, and understanding which tile it actually is on the tilemap very difficult. It also makes tile specific operations based on which tile it is very difficult. Try the download below to see it in action, or view the screenshot.

    The huge numbers fit with the operation done + what the id would be if it weren't altered. The altered number are different if x flipped, y flipped, xy flipped, rotated, rotated and x flipped, rotated and y flipped, and rotated and xy flipped.

    Is this a bug or intentional so GM internally knows all a tile's properties from one number by messing up the tile ids this way?

    Tile ID Changes On Flipping and Rotating
     

    Attached Files:

  2. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,510
    2d_warrior likes this.
  3. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,440
    2d_warrior likes this.
  4. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    201
    Ok I was getting the id from tilemap_get_at_pixel, after using tile_get_index on the result from that previous command I'm getting a correct result now. I thought the first command was for this, and it worked until I flipped and rotated tiles. Didn't know getting to the id required this many commands, or whether "tile data" meant id (apparently not). So the first command finds the tile mask then? Thanks!
     
  5. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,510
    If the tile has not been rotated or flipped etc then tilemap_get_at_pixel will return the tile index, but as soon as you you set those the bitmask is used to store this data so you then need to use those functions mentioned to get at it.
     
  6. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,440
    Tile data is not index.
    It's index and rotation info etc.
     
  7. 2d_warrior

    2d_warrior Member

    Joined:
    Jul 14, 2016
    Posts:
    201
    Does jamming those types of data together allow something useful to us? What's the purpose of having to do an extra step to get the tile id, lookup efficiency in the tile system or something?
     
  8. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,440
    Yeah it's very memory efficient, and it's ver efficient for the GPU to use that data too.
    It's better for cache, etc etc.

    You can also retrieve the tile index by andimg it with the tile index mask (I forget what the actual variable is but I'm sure someone here will know)
    Something like
    Code:
    var index = tilemap_get_tile(...) & tile_index_mask;
    
    Those function and variable names I made up since I don't remember them off the top of my head but you should be able to find the right ones in the manual.

    I think another great advantage is that in GM, we don't have structs. So returning the data like this is far more efficient than returning it as an array or something.
     

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