【发布时间】:2021-05-08 19:59:28
【问题描述】:
func spawnCircle(): #Spawn circle at random position every 3 seconds
var circle = TextureButton.new()
var texture = load("res://Assets/Circle.png")
circle.set_normal_texture(texture)
circleSpawnTimer.start(2.5) #spawn next circle
randomize()
add_child(circle)
circle.rect_position.x = randi() % int(rect_size.x)
circle.rect_position.y = randi() % int(rect_size.y)
circle.connect("pressed", self, "on_Circle_pressed", [circle]) #connect circle pressed signal and pass in its reference
var circleDisappearTimer = Timer.new() #Timer for circles to disappear if left unclicked
circle.add_child(circleDisappearTimer)
circleDisappearTimer.connect("timeout", circle, "queue_free") #delete circle on timeout
circleDisappearTimer.start(4) #After 5seconds left unclicked , the circle will disappear
我有一个圆形答题器游戏,一切似乎都正常运行,只是圆圈有时会在屏幕边缘生成,使其只有一半可见或只有四分之一可见。如何使圆圈仅在使其完全可见的地方生成?
【问题讨论】:
-
建议:用它的纹理、它的计时器和信号连接制作一个圆圈……进入一个新场景。然后实例化该场景,而不是在代码中完成所有工作(请参阅Instancing scenes)。您甚至可以将其
tree_entered连接到定位它的脚本。
标签: godot