0 votes

I want to save image located in a sprite.texture using json and load it.
Any help would be appreciated.

in Engine by (51 points)

i already created json file with some data but the images to be saved needs a json pro to teach us.

1 Answer

0 votes

Not sure what makes you believe storing an image path is any different from storing other information in JSON. I'd argue there is no such thing is a json pro": it's a way of writing down text-based information in a structured way, nothing advanced.

var data = {}

func save_game():
    data["image_path"] = $Sprite.texture.resource_path

    var file = File.new()
    var error = file.open("user://savegame.json", File.WRITE)
    if error == OK:

func load_game():
    var file = File.new()
    var error = file.open("user://savegame.json", File.READ)
    if error == OK:
       data = parse_json(file.get_line())

    $Sprite.texture = load(data["image_path"])
by (10,584 points)

perhaps he wants to store the image itself in the json, encoding to base64 or something?

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.