How to save player image input as a texture/variable?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By amberlimshin

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.

:bust_in_silhouette: Reply From: MrEliptik

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 =
$Sprite.texture = texture

If you want to save the image as a file:

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

See ImageTexture for more information ImageTexture — Documentation de Godot Engine (4.x) en français

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.

amberlimshin | 2021-03-22 02:37