this post was submitted on 10 Sep 2023
8 points (100.0% liked)

Godot

5750 readers
128 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 1 year ago
MODERATORS
 

Hi everyone, I was hoping someone could help me with the following. I have a button that saves a screenshot PNG to the Downloads folder when you press it.

What I want is for the button to disappear after it is pressed, so the screenshot does not include the two menu buttons called "%SaveReport" and "%BackMainMenu".

The code for the save button is listed below:

`

func _on_SaveReport_pressed():

$"%SaveReport".visible = false

$"%BackMainMenu".visible = false

print("I've disabled the buttons")
print("That means the screenshot SHOULD be button free")

take_screenshot()

$"%SaveReport".visible = true
$"%BackMainMenu".visible = true

`

As you can see, it calls the take_screenshot() function which is listed above:

`

func take_screenshot(): image = get_viewport().get_texture().get_image()

if OS.get_name() == "Web" or OS.has_feature('JavaScript'):
	print("We're on the web")
	# We're on the web		

	image.clear_mipmaps()

	var buffer = image.save_png_to_buffer()
	JavaScriptBridge.download_buffer(buffer, fileName)

if OS.get_name() != "Web" or !OS.has_feature('JavaScript'):
	# We're not on the web
	print("We're not on the web")
	
	var docs = OS.get_environment("HOME") + "/Documents"
	
	var title = str(docs + "/results",global_ints.observed_person_name, global_ints.observation_minutes,".png")
	
	print(title)
	
	var _saveimage = image.save_png(title)
	
	if OS.get_name() != "OSX":
		print("We're not on MacOS")
		var _openfolder = OS.shell_open(docs)
	
	if OS.get_name() == "OSX":
		print("We're on MacOS")
		
		var _openfolder = OS.shell_open("file://" + docs)

`

The code works. The screenshot is taken and it's saved to the Downloads folder and MacOS/Windows/Linux open up the Downloads folder straight after.

For the life of me, I can't figure out why the Back & Screenshot buttons ( "%SaveReport" and "%BackMainMenu") that I turn invisible BEFORE I call take_screenshot() end up being in the screenshot. Every single time.

Anyone have any ideas?

Thank you!

you are viewing a single comment's thread
view the rest of the comments
[–] bruce965@lemmy.ml 2 points 1 year ago

You will have to "await" the next frame after disabling the buttons, then take the screenshot and re-enable the buttons.

Otherwise you might be able to get the same effect by putting the buttons on a separate layer and excluding it from the screenshot (not sure if it's actually possible this way, but I strongly suppose so).