Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MadMelon999 |
Have you ever wanted to create a custom TileSet for your tilemap? Well here’s how to do it (only the basics though, I don’t know how to use autotile and stuff)! First, set up some basic vars:
# Cell Size
const CELL_SIZE = 16
# Collision
tile_collision = ConvexPolygonShape2D.new()
var poly_points = PoolVector2Array([Vector2(CELL_SIZE,CELL_SIZE), Vector2(0,CELL_SIZE), Vector2(0,0), Vector2(CELL_SIZE,0)])
tile_collision.set_point_cloud(poly_points)
# Region
const TILE_REGION = Rect2(Vector2(0,0), Vector2(CELL_SIZE,CELL_SIZE))
# Texture
null_texture = load(<png that is completely white/blank, with a size of your generic tile size>)
# Tile Set
tile_set = TileSet.new()
Now use the following function:
func add_tile(tile_name:String, tile_color:Color, tile_texture=null):
""" Create Custom Tile with color"""
# ID and Creation
var id = tile_set.get_last_unused_tile_id()
tile_set.create_tile(id)
# Name
tile_set.tile_set_name(id, tile_name)
# Region
tile_set.tile_set_region(id, TILE_REGION)
# Collision
tile_set.tile_set_shape(id, 0, tile_collision)
# Texture (if provided, then use texture, if not, then just modulate a blank texture (aka null texture))
if tile_texture == null:
# Color Texture
tile_set.tile_set_texture(id, null_texture)
tile_set.tile_set_modulate(id, tile_color)
else:
# Pre-Build texture
tile_set.tile_set_texture(id, tile_texture)
Feel free to comment any questions