-
-
Save paradrogue/634f1ee5b66968846478bf7bf21904c8 to your computer and use it in GitHub Desktop.
Quickly create a full TileSet on a TileMap with a single texture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tool | |
extends TileMap | |
export (Texture) var _texture:Texture setget _set_texture | |
func _set_texture(value:Texture) -> void: | |
if not Engine.is_editor_hint(): | |
return | |
_texture = value | |
if tile_set == null: | |
tile_set = TileSet.new() | |
tile_set.clear() | |
for id in tile_set.get_tiles_ids(): | |
tile_set.remove_tile(id) | |
var cells_h := int(_texture.get_width() / cell_size.x) | |
var cells_v := int(_texture.get_height() / cell_size.y) | |
for y in cells_v: | |
for x in cells_h: | |
var index:int = (y * cells_h) + x | |
var rect := Rect2(Vector2(x * cell_size.x, y * cell_size.y), cell_size) | |
tile_set.create_tile(index) | |
tile_set.tile_set_texture(index, _texture) | |
tile_set.tile_set_region(index, rect) | |
property_list_changed_notify() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment