0 votes

I know we can use the [img]res://icon.png[/img]

However, I am writing a Emoji Parser for chat and was curious if we could somehow use a spritesheet within the [img] tags instead of using hundreds of individual images. Any idea how to do this? Thanks in advance

asked Jan 3, 2017 in Engine by wombatTurkey (298 points)

Waaaaaaaaaait a minute, you can add images to a rich text label? Holy mother of jesus.

@mateusak what do you mean?

Just for curiosity tried this on a RTL and worked:

var texture = preload("res://icon.png")
var subimage = texture.get_data().get_rect(Rect2(10,10,10,10))
var subtexture = ImageTexture.new()

subtexture.create_from_image(subimage)  
subtexture.set_path("res://virtualpath/subtexture.png")

add_text(str("subimage: "))
append_bbcode(str("[img]",subtexture.get_path(),"[/img]"))

This code on RTL ready will cut a bit of icon file and create a new image from the texture then crop the image to make a new resource

So, it seems that will work, you need to find a good way to organize your "virtual resources", and maybe get rid of them when not used too.


Made this with zero knowledge on the subject so maybe there is a better/direct way to get the final resource, look at Texture, TextureImage, Image and related classes.
Try and share your findings ^_^

Please log in or register to answer this question.

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 How to use this Q&A? before posting your first questions.