HUD problem with Pong

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

Hi, I´m making a pong game and I have a problem with the HUD, the HUD it´s made from a canvas layer with 2 Labels and the problem is that points get subtract or attribute to the wrong player on occasions (like 1 or 2 times and a playthrough) then works fine, the points are attributed using signals and area2D, this is the code of the HUD:

extends CanvasLayer


var score_1 = 0
var score_2 = 0

func _ready():
	pass
func update_score():
	$Score_1.text = str(score_1)
	$Score_2.text = str(score_2)
func _on_Meta_1_body_entered(_body):
	update_score()
	score_1 += 1
func _on_Meta_2_body_entered(_body):
	update_score()
	score_2 += 1
:bust_in_silhouette: Reply From: exuin

I think you should call the update_score function after you add the 1 to the score. Otherwise it will show the score increase the last time the score was updated instead of the current time.

thanks, that solve the problem

Lucky_Mouse | 2021-01-19 05:33