0 votes

Hi guys.

I have this issue: I have created a spawner that creates infinities objects(KinematicBodies2D). When an object touches an Aread2D then the object disappears(i use signal from Aread2D to object).What i want, is when the object touches the Area2D then a GUI counter high on the screen to show me the score (counter=counter+1). i did a try with a signal from Area2D to a Label but a Label accept only strings.I searched on YouTube but there is no an appropriate video about this case. I show some videos that some guys that were using labels and that was weird...Is there an appropriate node that accepts integers?Any idea please?

Thank you.

in Engine by (223 points)

try keep a var score in the area2D's script and then just display it on the label

First of all thank you very much about your reply.Basically i used the "text" Label's property and then "set_text(str(score))". So, i managed to show the score on the Label but now the problem is that every number is written on the previous one ...

1 Answer

+1 vote

Hey Nick888.

A script like this should work:

extends Area2D
var counter = 0
onready var Label = get_node("Container/Label") # path to your label

func _on_area2d_body_entered(body): # connect the signal to this 
    if body.is_in_group("Enemy"): # you can also use another way
        counter += 1
        Label.text = str(counter)

if that's what you've done I don't know what you mean with 'written on the previous one'. Hope it helps to make things clearer

by (864 points)

Thank you so much about your reply!

The issue was that because of the Area2D was together with the Label in a scene 2, the scene1(main scene) was running all the time the scene 2.So,thats why the string-numbers was one over the other.
So, i applied a personal trick and i solved the problem:I created in main scene an Aread2D over the Aread2D of scene2 and i deleted the Label of scene2.Then, i created a personal signal and i send it from the Ared2D of scene1(main secene) to the new Label of scene1(main scene).

Thank you again for your concern and i am sorry about my english.Its not my native language.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.