I am making a simple turn-based movement demo in Godot. It features three sprites that are the default Godot icon. The demo is meant to demonstrate each sprite taking one movement (with a singular press of the right arrow key by the user) before going to the next two sprites to make their movement. Then, the queue would restart from the beginning. The hierarchy of the nodes goes:
- Sprite 1
- Sprite 2
- Sprite 3
The parent, Node2D, is meant to manage the turns of each child. The code is below:
players = get_children()
active_character = players
active_character = players[(active_character.get_index() + 1) % get_child_count()]
On the start of the game,
_ready() gets the list of children, and starts the queue on the first child in the hierarchy of nodes. The
print functions are only there for myself to make sure that turns were going properly.
The first child has the following code:
var velocity = Vector2(0, 0)
var speed = 200
TQParent = get_parent()
velocity.x = 50
global_position += velocity * speed * delta
The second and third children have the same code, except the
TQParent.play_turn() call is taken out. Functionally, I understand that this does not make sense. However, my output shows me that each subsequent keypress of the right arrow key goes to the next node in the list and restarts after the last one. This is my desired result. Yet, all of the sprites are moving at the same time and not one after the other with each keypress.
I understand this is likely not the best way to structure everything. I have messed around with the placement of
TQParent.play_turn() in each script, the placement of the
yield() function, etc. Yet, this is the closest I have come to to getting my desired result.
I am still new to Godot, and all help is appreciated. I've been dealing with this problem on the turn queue for a while now. I am willing to go to any length necessary to get this fixed. I will be as active on this post and the forum as possible. Thanks so much!