Need Help with Timer Not Acting Properly

CanvasLayer doesn’t have and positional properties, You would have to target it’s children. If it has many children, put them all under a single Control node and modify that position

I did thumbs up to say “correct”

Okay, I want to transition the score label in particular - I tried changing the first inupt, the object I want to use, to “$ScoreLabel” instead of “self” like the first time, but it still thinks position is not declared in the current scope. What is the appropriate syntax/formatting in this case?

Okay, I think I figured it out, I just have to add the $ScoreLabel before the position when I use is an input, and then it doesn’t give errors.

However, I haven’t actually playtested it yet, but it should work if it’s not highlighting it in red anymore.

1 Like

Unfortunately, it doesn’t work and crashes the program as soon as it is called, stating it “cannot convert argument 2 of the function from Vector2 to NodePath”.

So instead, what is the proper syntax I should use to get the transition I want?

This is what the crashing line looks like in particular:

jump_tween.tween_property($ScoreLabel, $ScoreLabel.position, $ScoreLabel.position + Vector2(0, -40), 0.5).set_trans(Tween.TRANS_QUAD)

And I will change the Vector2 to make it transition from the right edge of the screen left to the center, right now I’m just copy pasting the third argument from the old function to playtest that it works in general.

jump_tween.tween_property($ScoreLabel, $ScoreLabel.position, $ScoreLabel.position + Vector2(0, -40), 0.5).set_trans(Tween.TRANS_QUAD)

The second argument is weird, it’s a path from the first argument in string form. So you want to change $ScoreLabel.position over timer, we split the object $ScoreLabel into the first parameter, then the property into the second, as a string.

jump_tween.tween_property($ScoreLabel, "position", $ScoreLabel.position + Vector2(0, -40), 0.5).set_trans(Tween.TRANS_QUAD)

Oh, that’s why, using the same syntax as the example you gave me and the tween API gives me for the second argument.

Okay, so looking on the Tween page in the official Godot API I find this tween for modulating color:

tween.tween_property($Sprite, "modulate", Color.RED, 1)

That makes perfect sense to me, but my question is what should I do if I want to modulate visibility, because I want a very dark rectangle to fade in over the background when you get a game over, and the message to modulate its color to white to stand out against the background, just like it’s black now for the same reason?

you can make a color with a low alpha, maybe using the .from to specify a starting value.

var transparent := Color(1, 1, 1, 0)
tween.tween_property($Sprite, "modulate", Color.BLACK, 1).from(transparent)

This example goes from a transparent white to a opaque black

That’s an awesome workaround. Thank you!

Okay, here is my code for the HUD now, making sure to set the screen background alpha to 0 rather than the default 255 first so it starts fully transparent:

extends CanvasLayer
var message_tween: Tween
var color_tween: Tween

func show_message(text):
	$Message.text = text
	$Message.show()
	
func show_game_over():
	show_message("Game Over")
	message_tween = create_tween()
	message_tween.tween_property($Message, "position", $Message.position + Vector2(-760, 0), 1.0).set_trans(Tween.TRANS_QUAD)
	var transparent := Color(1, 1, 1, 0)
	color_tween.tween_property($BackgroundScreen, "modulate", Color.BLACK, 1).from(transparent)
	
func update_score(score):
	$ScoreLabel.text = str(Globals.score)
# Called when the node enters the scene tree for the first time.

Unfortunately, I get a crash that I cannot call method “tween_property” on a null value on the line about the color tween in particular.

What should I do to fix that?

Gotta create the tween first, like you did for message_tween above

color_tween = create_tween()
color_tween.tween_property($BackgroundScreen, "modulate", Color.BLACK, 1).from(transparent)

Silly me. Makes sense!

Now it works perfectly. Thank you so much!

Okay, so I tried this code to modulate the message color to white from black:

	messagecolor_tween = create_tween()
	messagecolor_tween.tween_property($Message, "modulate", Color.WHITE, 1).from(Color.BLACK)

Unfortunately it doesn’t happen, how am I supposed to type it correctly?

Like it stays black no matter what, which isn’t what I want

modulate is a strange property. It multiplies the color, so when you take black text (0, 0, 0) and multiply it by white (1, 1, 1) you still get (0, 0, 0). Maybe it’s parent is modulated black? Is the font color black?

Yes it is black already - what should I use instead?

That is, what should I use instead of “modulate”

use modulate, make it white