1
\$\begingroup\$

I am seeking possibility to switch character textures for game, even after I have compiled and built the binary.

For example I have a troll with a Sprite from "/assets/texture1.png"

Now after the game has been released, I can change this sprite.

Currently I have found this method

func _ready():
    var texture = load("res://textures/troll1.png")
    sprite.texture = texture

But after the export, when I change the troll1.png, the texture in the game remains the same.

\$\endgroup\$
0
\$\begingroup\$

I have found an answer to my question.

First mistake i did, was that i did not copy my assets folder to my game export folder, so the game never found the assets, pretty dumb...

Also, i will put some methods how to load images without using Godot automatic importer.

The simplest is this method

var texture = ImageTexture.new()
    texture.load("textures/troll1.png");
    $Sprite.texture = texture

And 2 methods that was posted on reddit

https://www.reddit.com/r/godot/comments/eojih/how_to_load_images_without_importer/

var file = File.new()
var image = Image.new()

file.open("/path/to/image.png", File.READ)
image.load_png_from_buffer(file.get_buffer(file.get_len()))

file.close()
image.lock()
var path = "/path/to/image.png"

var file = File.new()
var image = Image.new()

file.open(path, File.READ)
var buffer = file.get_buffer(file.get_len())

match path.get_extension():
    "png":
        image.load_png_from_buffer(buffer)
    "jpg":
        image.load_jpg_from_buffer(buffer)

file.close()
image.lock()

var texture = ImageTexture.new()
    texture.create_from_image(image);
    $Sprite.texture = texture

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.