Hi! I'm new in Godot and I'm trying to recreate a Tetris game. I saw a Unity tutorial and I want to do something similar with Godot.
The problem that I have is, that my spawner creates just one Tetromino as a child and nothing more.
I'm using a custom signal to tell the "Game" node (main), that a Tetromino can't move anymore and should add another child to the game.
I guess this is because I added a set_process(false)
, but I don't understand why this should affect all the instantiated scenes too. Anyway, here's my code:
Game (main):
func _ready():
makeTetromino()
$BlockT.connect("newT", self ,"makeTetromino")
func makeTetromino():
var scene = load("res://BlockT.tscn")
var instance = scene.instance()
instance.position = Vector2(486,57)
add_child(instance)
BlockT (tetromino):
func _process(delta):
var x = timeFall/15 if Input.is_action_pressed("ui_down") else timeFall
if(OS.get_ticks_msec() - start > x):
self.position.y += unity
start = OS.get_ticks_msec()
if(!canMove()):
self.position.y -= unity
emit_signal("newT")
set_process(false)
func canMove():
for child in self.get_children():
var x = child.get_global_position().x
var y = child.get_global_position().y
if(int(x) < 0 or int(x) > width*unity or int(y) >= height*unity):
return false
return true`
PD. I tried to do it too with a timer and at the end delete it, so the tetromino stops moving, but I got the same result.
What am I doing wrong?
Thanks!