#Storing tiles' custom data in variables using Atlas Textures

1 messages · Page 1 of 1 (latest)

neat ore
#

This is a tycoon game using isometric view and coordinates

I've been brainstorming ideas about the best way to assign custom data to specific tiles in an atlas texture. (ie: assign a value to a grass tile allowing me to define it as terrain in a script, assign a bool to define the block as solid or not, etc.)
The big challenge here is I'd much prefer not hard coding these properties so that I can add new tileset assets without changing code. I'll still go the hard coding route if it turns out to beat all the other methods but I still thought it was an interesting subject especially as I've barely found any example or information about how game devs usually store data of tiles that are part of a AtlasTexture/tileset

Here's my take on it: storing the data as pixels in the spritesheet (I'll post a picture of my spritesheet template below)
This spritesheet is for 128x128 tiles but the game can handle different sizes.

This way I just need to edit the spritesheet and I can put it in my game, the scripts will handle the logic and organize the data.
When a tile is placed, it's data will be stored in a dictionary with the tile's position as it's key
This is very useful in the early development stage as we frequently reorder, change and add tilesets.

issue #1: What equation do I need to get the tile size of tiles that aren't squares?

if the tiles are squares, I just need to divide the height of the texture by 2 to get the tile size, but this logics break for tiles that aren't squares.
I feel like there should be an equation that solves that but I haven't gotten my finger on it yet.
I could also store that value as pixels but an equation would be best.

issue #2: encoding strings with bits is tedious and It may complexify traducing the game in another language.

issue #3: This technique may overall take more time to implement than to hard code each tiles.

I've never seen any tilesets like mines in a game before. Am I totally crazy to do that ? Am I missing another option that is superior to the other ones above ?
I won't list all the pros and cons of my method but comparing it to hard coding I found that so far, they kinda balance each other out.

I'm opening a discussion on this subject because I probably missed big pros and cons of each method and may be oblivious to other methods.
What do y'all think ?

ruby gate
#

not really sure if there is a (clean) way to do it without hardcoding properties really

#

maybe you could try somehow messing around with scenes in tilemaps? although not sure how great they would be for storing and accessing data

#

can't really seem to find a way to access data from scenes in a tilemap

ruby gate
#

you can add custom scenes to tilemaps

neat ore
#

Storing tiles' custom data in variables using Atlas Textures

#

I think my title may have been misleading. It actually doesn't matter in the problem that I'm using a tilemap, it's all about the AtlasTexture.

#

Although I am still gonna look into custom scenes and see if it may help. Thanks for the insight Cookie !

neat ore
#

After doing some research on custom scenes it indirectly made me think of a nice compromise between hard coding and my pixels. I'm going to encode a single unique value using pixels for each tiles, think of it as a tile ID. I can then use this number to reference it's properties.
It allows a lot of freedom when it comes to editing the visual of the tile and it's properties while preserving that constant numbers that links them together.
Wherever a tile is, on whatever spritesheet, I will always be able to link it to it's respective properties which have remained in the same place in the code regardless of how the sprite nodes are ordered in the tree.