Hi Community!
In my game the player can drop tiles to build a tower. The tiles are RigidBody2D nodes and hence use the physics engine. The tiles are created on clicking LMB and are instanced as children of my level. Dropping tiles should only be possible when the prior tile is on the ground and no longer moving.
So I want my tiles after entering sleep mode to emit a signal to my level node to make it possible to drop the next tile. The signal should only be emitted once as soon as the tile comes to rest. It is possible that later tiles force prior tiles to move again and at this point the "old" tiles should NOT emit this signal again.
The signal code in my tile.gd:
func _on_Tile_sleeping_state_changed():
emit_signal("sleeping_now", CONNECT_ONESHOT)
print ("Going to sleep now! (TILE)")
The code in my level.gd:
func _input(_event):
if Input.is_action_pressed("left_mouse_button") and timer.is_stopped():
if dropped_tile_asleep == true:
...
$Tiles.add_child(dropped_tile)
dropped_tile.connect("sleeping_now", self, "on_tile_is_sleeping")
...
func on_tile_is_sleeping(tile):
print ("OK, good night! (LEVEL)")
dropped_tile_asleep = true
The signal works, but the oneshot thing does not. The print entries tell me, that the signal also fires again when tiles are moved by other tiles. Did I misunderstand how CONNECT_ONESHOT works or is my code wrong?
Thx for reading
Cavas