0 votes

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 ?

in Engine by (12 points)

1 Answer

+1 vote

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: https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/gdscript_advanced.html#arrays

by (129 points)

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 ..

But thanks fot the anwer =)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.