+4 votes

I have all my icons packed in a single texture, which is great when I'm using them in sprites, but now I want to use them in my UI - I'd like to position several icons next to each other using an HBoxContainer.

My problem is that I can't work out how to only display ONE of my icons from the texture using a TextureRect - I can only display the whole texture (using stretch mode: tile, I can show only part of the texture, but it's always the top-left part)

I tried using sprites instead, because I can provide a UV offset with those, but I couldn't get the HBoxContainer to control their positions. My options seem to be to divide the icons into individual textures, or maybe write a shader, but I'm hoping I'm missing something obvious.

Is there any way to show a specified part of a texture using a TextureRect or other control node?

in Engine by (31 points)

1 Answer

+8 votes
Best answer

TextureRect indeed doesn't have a region property like Sprite, so you may have to create an AtlasTexture instead: https://docs.godotengine.org/en/stable/classes/class_atlastexture.html

Note: the description is misleading. AtlasTexture doesn't "contains" multiple textures, it actually references a sub-region of a larger texture instead. They are lightweight and aren't copying pixels.

by (28,970 points)
selected by

Thank you! (I'd resigned myself to using sprites and managing their positions myself, which would have been a shame)

Should be renamed to TextureRegion.

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 Frequently asked questions and 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 [email protected] with your username.