0 votes

There'll be a simple painting app minigame. How do I save the player input (painting) as a texture that can be used later on in the game on other sprites?

For example, the player paints an elephant. The minigame ends. But later in the game in another level/scene, I want to display the player's input on a painting in a room.

What's the best way to save the player's elephant painting for later use?

Thank you so much. I really appreciate it.

Godot version 3.2
in Engine by (29 points)

1 Answer

+1 vote
Best answer

You can get the data from the viewport (or any texture like sprite, colorrect, etc..) with:

var data = viewport.get_texture().get_data()

If you want to easily edit that later, you could save this data. Then later you create a texture based on the data:

var texture = ImageTexture.new()
texture.create_from_image(data)
$Sprite.texture = texture

If you want to save the image as a file:

var img = viewport.get_texture().get_data()
img.flip_y()
img.save_png(path)

See ImageTexture for more information https://docs.godotengine.org/fr/stable/classes/class_imagetexture.html

by (617 points)
selected by

Duuudee, I have downloaded a bunch of demos on GIT and couldn't make sense of the code on it. Or like I didn't even know the terms needed to search this. Thanks man for putting it in layman terms.

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.
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 webmaster@godotengine.org with your username.