![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Rzymon |
Hello, I’m trying to create inventory. I’m using ItemList for this.
I see that people use *.png or *.tex files for each item, when they adding items to ItemList.
I wanted to do something more flexible for items (IMHO It’s inefficient for me, to have 100 separated *.png files if you have 100 items in your project). I saved few items in one (f.e.) items.png file, and I created TileSet using Sprite nodes and setting Texture region for each Sprite and I exported all to TileSet.
Next I created scene with ItemList and I wrote this:
extends Node
onready var itemList = get_node("Panel/ItemList")
onready var items = preload("res://Core/Scenes/Tilesets/Items32x32.tres")
func _ready():
itemList.max_columns = 9
itemList.fixed_icon_size = Vector2(32,32)
itemList.icon_mode = ItemList.ICON_MODE_TOP
itemList.select_mode = ItemList.SELECT_SINGLE
itemList.same_column_width = true
var item = items.tile_get_texture(0) #Spirte with ID=0 from TileSet
itemList.add_item("", item, true)
But when I play scene I have whole *png but scaled to one item slot.
How can I get one tile from TileSet to put it to my ItemList? Or maybe I’m doing something wrong, so what is the best way to store multiple items texture?
Did you define the sprites and corresponding rect information inside your Tileset scene as it is explained here?
rolfpancake | 2018-02-19 13:01
Yes. This is my scene which I exported to TileSet. Every Sprite has it’s own region set in properties.
Rzymon | 2018-02-19 13:13
Alright, I know it’s been a year since this question but I just had the same issue and was able to solve it
First I wanna start off by saying that my inventory UI system is based on the fact that the logic will pass to it an array of instances of scenes (the items scenes).
The item scene has a Sprite Node which taxes the ENTIRE TILESET TEXTURE and grabs a region from it, so that it takes the single sprite that corresponds to the particular item (which is the proper to handle sprites anyway, screw dealing with hundreds of png’s lol)
Now, considering the above I did this:
func setInventory(items):
var id = 0
for item in items:
var itemSprite = item.get_node("Sprite")
$CanvasLayer/Container/ItemList.add_icon_item(itemSprite.texture)
$CanvasLayer/Container/ItemList.set_item_icon_region(id, itemSprite.region_rect)
id += 1
Solanich | 2019-02-10 01:45