How do I use a TileSet in Script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SuperPrower

I have created a TileSet with editor UI, with 4 Atlas Tiles. I have a Script that inherits Node2D (but that’s not enforced).

I want to draw a single tile from one of four Atlas Tiles. How would I do this, other than taking a texture tile_get_texture, then getting tile boundaries tile_get_region, autotile_get_size, tile_get_texture_offset, and then somehow (with Sprite or the TextureRect) cropping the texture with the boundaries?

:bust_in_silhouette: Reply From: The_Black_Chess_King

You are trying to do it by code, maybe you can use the built tileset editor?

  1. I am already using a tileset editor to cut a texture into the tiles. I now need to extract those tiles from the tileset.
  2. I am implementing a procedural generation algorithm, so I don’t think I can use an editor UI for that.

SuperPrower | 2019-11-06 03:21

Okay, what about this one?

Procedural Generation in Godot - Part 3: Tile-based Infinite Worlds · KCC Blog

The_Black_Chess_King | 2019-11-06 03:33