#Can you use dynamically created ImageTexture in a Sprite texture without saving it to disk?

5 messages · Page 1 of 1 (latest)

rough birch
#

I tried to use dynamically ImageTexture that was created from Image created in code for a Sprite texture, but it seems that all set_pixelv operations aren't loaded with it (I just get the fill function working), unless I save it to a disk or use it for TextureRect (which has purpose UI, while I would like to manipulate Sprite textures during the game but currently I am just trying to see if that's even possible by using dynamic ImageTexture). Is there anyway I could make my ImageTexture working as a Sprite texture without the need of saving it up to disk and then reloading it or is it simply not possible in Godot 3.6? Here is how the code looks like:

func _ready():
    var spriteTexture: ImageTexture = ImageTexture.new();
    var image: Image = Image.new()
    image.create(50, 50, false, Image.FORMAT_RGBA8)
    image.fill(Color8(255,255,255))
    image.lock()
    image.set_pixelv(Vector2(6,6), Color8(0,0,0))
    image.set_pixelv(Vector2(35,22), Color8(0,0,0))
    spriteTexture.create_from_image(image)
    texture = spriteTexture
kindred void
#

you're locking the image after the fill, preventing any other edits.

rough birch
# kindred void you're locking the image after the fill, preventing any other edits.

Documentation specifies you have to lock an image in order to use pixelv, so that's clearly not true, unless documentation for 3.6 is outdated :
https://docs.godotengine.org/en/3.6/classes/class_image.html#class-image-method-set-pixelv

#

Also if that was the case, saving an image afterwards on a disc would mean it should only have fill color, but I already tested it and when you save an image to a disc, it has all the colors including pixelv and that issue isn't even existing in TextureRect, can send screenshots to demonstrate that code works for the above.

kindred void
#

oh my bad, i'm not that experienced with image textures, so i was unaware of the role locking has.