TextureAssets.Item[id] returns an Asset<Texture2D> of that item. If you're unsure of whether the item's asset will be loaded (1.4 uses asynchronous asset loading), request the asset manually with ImmediateLoad instead of AsyncLoad.
hello, I'm making my client for a terrarium with ImGui and I want to make an item giver, but I don't understand 2 things in 1 how to get the texture of an object by ID and in 2 how to create buttons, I tried to create them through foreach, but nothing worked for me
TextureAssets.Item[id] returns an Asset<Texture2D> of that item. If you're unsure of whether the item's asset will be loaded (1.4 uses asynchronous asset loading), request the asset manually with ImmediateLoad instead of AsyncLoad.
C# programmer.
convicted tomatophile#0001
how can i display the texture? when using imguics it displays a white square instead of a texture i use https://******.com/0x0ade/ImGuiCS/bl...GuiXNAState.cs
- - - Updated - - -
~~And the problem is not even in imgui, the problem is that this method returns Assets, that is, it is not automatically compatible with imgui / xna. The question is how does terraria render such textures?~~
oh i just had to add .value
- - - Updated - - -
i finally fixed my problem
but when i try to display exactly the texture from the terraria i get a white square
as far as I understand, the problem is in imgui or my parameters of the button with a picture, since I made a completely working method for obtaining texture by ID here are the codes
public static Texture2D GetTextureByID(string type, int id, GraphicsDevice graphicsdevice)
{
var tx = new Texture2D(graphicsdevice, 20, 20);
if (type == "item") { tx = Main.instance.Content.Load<Texture2D>("Images\\Ite m_" + id); }
if (type == "npc") { tx = Main.instance.Content.Load<Texture2D>("Images\\NPC _" + id); }
if (type == "projectile") { tx = Main.instance.Content.Load<Texture2D>("Images\\Pro jectile_" + id); }
if (type == "buff") { tx = Main.instance.Content.Load<Texture2D>("Images\\Buf f_" + id); }
return tx;
}
ImGui.ImageButton(ImGuiState.Register(texture), new ImVec2(50, 50), new ImVec2(0, 0), new ImVec2(0, 0), 0, new ImVec4(1, 1, 1, 1), new ImVec4(1, 1, 1, 1));
I FIXED IT!!!!!!!!!
Last edited by ItsMakar; 12-17-2021 at 09:20 AM.
it works but i can't filter items because text input doesn't work any idea how to fix it? I use the ImGuiXNA renderer and apparently the problem is in it
ImGuiXNA is outdated and pretty bad, consider using ImGui.NET