What I'm doing ?:
- I'm trying to have a scene for a player to customize the player outfit.
- The player Sprite is made of 3 sprites: body, eyes & mouth.
- There are independant png images for the different bodies, eyes and mouths.
The code I'm trying:
# Create Image objects and load the png's
var body = Image()
var eyes = Image()
# TRY1 - Draw the eyes over the body
body.blit_rect(eyes, Rect2(0,0,100,100), Vector2(15, 20))
# TRY2 - Brush the eyes as a mask on the body
body.brush_transfer(eyes, eyes, Vector2(15, 20))
# Save the image to new route
TRY1: This almost did the trick but the problem is the eyes are not "drawn" over the body so the background is empty.
Example generated Image:
It's not quite clear but the space between the eyes is transparent, and what I need is to see the body under the eyes
TRY2: I don't quite understand the functionality of brush_transfer and couldn't find any good example, maybe anybody can point me to some tutorial on this. When I save the image using
brush_transfer only the body image is shown
- Is there any better way to achieve what I'm trying to do ?
- Is there any way to get an
Image object from a
- Is there a way to
set_modulate on a
- Is there any good tutorial besides the official docs about editing images programmatically ?
I started a few days ago with Godot and everything is new to me, I just checked the offical docs and this site. If there is any other good forum or page I can check for help I appreciate any recommendation.
I tried to achieve something like @raymoo suggested using a Viewport.
My goal was:
- Add an "invisible"
Viewport into my scene ( I don't need the user to see this Viewport)
- Draw 3 sprites on the viewport (Body, eyes & mouth)
- Get an
Imageobject from the Viewport with:
- Save the image to
Assetsto use it later
My problem is the
get_screen_capture() is allways empty. I tried all the configuration I could and check all the properties of
Viewport on the official docs. I also used
get_screen_capture() on the main viewport and works fine, it returns a screenshot of the game.
- Why the "sub" viewport I created return an empty png ?
- I looked for information about initializing a Viewport programmatically but found nothing. Can someone suggest how a Viewport can be initialized ?
- Is possible to have this Viewport outside the visible game ? I just need this Viewport to generate a custom image, I don't need the user to see this
The code I've tried with Viewport solution (This code is inside a script that belongs to a Node on my main scene):
var body_texture = preload("res:/path_to_body.png")
var eyes_texture = preload("res://path_to_eyes.png")
var body = Sprite.new()
var eyes = Sprite.new()
var vps = Viewport.new()
var result = vps.get_screen_capture()