Attach a script to tile

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

Hey Godot people !
The question have been asked multiple time but always people said it’s a feature request.
Today how do you attach a script to a tile in a tileset?
I want to make each of my tile desctructible, some tiles have differents frictions , some tiles have data in it ( I want to create a air pressurization system ).
How do you guys manage this stuff today ? I have to place each node one by one ? Create a tilemap editor ?

:bust_in_silhouette: Reply From: aa

I’d create a control node that manages all the map state. In this node I’d have a two-dimensional array that contains all the specific tile data. For what you’re talking about I’d do it something like this (let’s assume your map is 10x10 tiles):

var map = []
for x in range(10):
    map.append([])
    for y in range(10):
        map[x].append([true, 0, 0])

So what’s going on here? We create an array called map to which we append 10 “columns.” Each of these columns in turn will hold 10 “rows.” In each of these row/column positions we have the tile data itself in yet another array. This final array holds variables like destructibility (being true by default,) it’s friction and it’s air pressure.

Let’s say we want to set the tile at (3, 4) of our map to be non-destructible. We would then access the 0th variable of the tile array, located within the 3rd position of the “columns” and the fourth position of the “rows.”

map[3][4][0] = false

Read more about arrays here: GDScript: An introduction to dynamic languages — Godot Engine (3.1) documentation in English

I know arrays, I have good programming background. But I have another issue. If I want to damage a tile and change its sprite when it’s damaged.
Think of terraria or rimword , they don’t use tilemaps i guess …

Prakkkmak | 2020-01-03 12:57

But thanks fot the anwer =)

Prakkkmak | 2020-01-03 12:58