Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

TileMap component not consistent with API

Discussion in 'Project Tiny' started by vincismurf, Dec 17, 2018.

  1. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    200
    I am looking to dynamically change the tiles on the Tilemap at runtime. In order to do so I need access to a tile's sprite. I made a component and added a Tilemap2d.TileData property to it which allows me to set the sprite in the editor. However on the code side it considers the tileData.tile property an Entity.. . . which causes all sorts of head aches. Most importantly I don't have access to the sprite.

    I also tried using a Reference to a Entity with a SpriteRenderer, access to the sprite is cleaner but nothing renders.

    Could any one point me in the right direction
     
  2. Berzee

    Berzee

    Joined:
    Sep 3, 2013
    Posts:
    11
    The best way I've found to access the sprite is something like this:
    Code (JavaScript):
    1.  
    2. this.world.usingComponentData(tilemap.tiles[tilemapIndex].tile,[ut.Tilemap2D.Tile],
    3. (tile) => {
    4. tile.sprite; //access the sprite thusly
    5. });
    6.  
    This page describes TileData.tile as "Reference to an entity with a Tile component. Tile to display."
     
  3. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    200
    Noted, it still treats that sprite as an Entity.. . . luckily there is a Tile Entity one can add to a component. that seems to get me what I needed.

    Question do we know if the RuleTile will work with Tiny? Does it need to be ported to TypeScript?