Add UI to tiles?
Asked Answered
L

6

0

Hi there,

is there some kind of ingame canvas that would be suited to add UI to tiles?

Imagine civilization for example... showing ressources.
Or to be more basic: Showing the coordinates on the tile.

So far I just use the normal tiles with a 2d tileset, nothing special added

Lytic answered 11/3 at 17:15 Comment(0)
M
0

Lytic
for coordinates, i would spawn a label
Godot.Label lab = new Godot.Label();
set the parameter like text, color, position and font
and add it as a child to the tilemap or an other parentnode with AddChild
and so you can switch the coordinates on/off with the visible-flag

Momus answered 11/3 at 18:6 Comment(0)
G
0

Not sure if you have found this yet, it is a bit hidden: You can add custom_data to your tiles (custom_data_layer). So you can store things like the number of resources etc. directly with your tile. So you could have a little UI node (just a label or a complete UI scene with a panel and a number of subnodes like texture rects, labels etc.) in your scene tree that normally is invisible and that you just move to the position where you want to display it (top right corner of the tile, for example), fill it with the data from the tile and make visible when the player hovers over it with the mouse, for example.

Gypsy answered 12/3 at 9:8 Comment(0)
L
0

Momus Thank you! My main concern would be where to add that Label.

Doesn't it need some kind of canavas node? In Unity for example you would add a small canvas to the cell, which on the other hand would be some kind of object I guess...

Also tried your code, but it didn't work for me. He doesnt want an identifier after Godot.Label

Gypsy I'm aware that there is custom_data... which is usually used to define it a tile slows down movement etc. I just don't know if labels are the right solution and where I would add these. Do I want like 200 or even more 'label' scenes spamming my scene tree? Does that mean I want every tile to spawn a 'scene' in the end? Wouldn't that deny the advantage I got by using godots grid instead of just spamming tiles myself?

Lytic answered 13/3 at 19:23 Comment(0)
G
0

Lytic
I was thinking just one label (or a small container) and you then just change the position when you display it. You can make it a subnode of the tilemap itself, for example. And then, when the user hovers over a tile, you move it next to the tile and make it visible. Or do you want to display the information all the time, so that it is visible for all tiles at once? In that case, I would create the nodes dynamically, as Millhon suggested. They are then all technically children of your tilemap (or whereever you want to put them), but they won't show up in your editor, because they are only created in runtime.

Gypsy answered 13/3 at 20:14 Comment(0)
L
0

Gypsy Yeah, wanna display them all the time... so the label can be displayed without any canvas or such? I will check it out

Lytic answered 15/3 at 18:13 Comment(0)
G
0

Lytic
Yes, in a 2D Viewport, you can mix and match Nodes2D and Controls. They will move around with the camera, though (which is something you probably want for your usecase anyway). If you want them to keep their position (like a HUD or a menu), you have to put them into a separate CanvasLayer.

Gypsy answered 16/3 at 8:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.