I made Pong game with Godot a couple of years ago and now came again to Godot.
This time I started a new game with really nothing more then date in one corner that is incremented each second and ability to pause that increment by pressing Space.
Ive had a hell of problems with aligining and positioning UI elements, in this case Date should be aligned to the top right edge of the screen. Date(Label is contained in a HBoxContainer which should later also have other controls. Finally managed to somehow do it with the help of Layout,. Now it looks ok in IDE but when run there is space to the right of Label which should NOT be there.
The second problem is with pressing Space - pausing. If pressed briefly its mostly not registered by the code, but if you press and hold it longer it behaves as pressed twice.
Here is the code:
func _process(delta):
TimePassed += delta
if Input.is_action_pressed("ui_accept"):
paused = not paused
if paused:
$VBoxContainer/Pauza.text = "Paused"
else:
$VBoxContainer/Pauza.text = ""
if (TimePassed >= TimeWait) and not paused:
TimePassed = 0
adjust_date()
func adjust_date():
var day = 0
var month = 0
var year = 0
var cday = ""
var cmonth =""
var cdatum = ""
var datum = get_node("HBoxContainerDesno/Datum")
day = datum.text.substr(0,2).to_int()
month = datum.text.substr(3,2).to_int()
year = datum.text.substr(6,4).to_int()
if month in velikiMeseci:
if day == 31:
if month == 12:
month = 0
year +=1
month += 1
day = 0
elif month == 2:
if day == 28:
month += 1
day = 0
elif month in maliMeseci:
if day == 30:
month += 1
day = 0
day += 1
cday ="%02d" % day
cmonth = "%02d" % month
cdatum=cday+"."+cmonth+"."+str(year)
$HBoxContainerDesno/Datum.text=cdatum.strip_edges()
You can also comment on improving code, Id appriciate any input
EDIT: I also lost indentation while copying code here so you can help me with that too π
Ok, I found a post which explains fomating code segment
Z.