![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Ph_Pheo |
Hi
In my project I’m spawning 3 Icons at the start of the game and put them in a Icon group
The Icons have each a MyNbr
variable that goes from 0 to 2.
When I press the enter key, i execute this code:
if Input.is_action_just_pressed("ui_accept") and MyNbr == 0:
emit_signal("Dead", MyNbr, position)
self.queue_free()
The parent node receive the signal and launch this code:
func icon_moving(newMyNbr, newPosition):
for Icon in get_tree().get_nodes_in_group("Icon"):
if Icon.MyNbr == newMyNbr + 1:
Icon.position = newPosition
Icon.MyNbr = newMyNbr
What I’m trying to do is make the Icon with a MyNbr
of 1 take the position and the MyNbr
of deleted Icon.
The problem is that when i use Icon.MyNbr = newMyNbr
, the icon that receives that newMyNbr
is also deleted.
How do I fix this ?
Here is the full code for the parent
extends Node2D
onready var Icontscn = preload("res://Sprite.tscn")
var ChildNbr = 0
var SpawnPos = [Vector2(100,100), Vector2(100,200), Vector2(100,300)]
func _ready():
for number in range(3):
icon_spawn()
func icon_spawn():
var IconInst = Icontscn.instance()
add_child(IconInst)
IconInst.connect("Dead", self, "icon_moving")
IconInst.position = SpawnPos[ChildNbr]
IconInst.MyNbr = ChildNbr
ChildNbr += 1
func icon_moving(newMyNbr, newPosition):
for Icon in get_tree().get_nodes_in_group("Icon"):
if Icon.MyNbr == newMyNbr + 1:
Icon.position = newPosition
Icon.MyNbr = newMyNbr
And here the full code of the Icons
extends Sprite
signal Dead
var MyNbr = 0
func _ready():
add_to_group("Icon")
func _process(delta):
if Input.is_action_just_pressed("ui_accept") and MyNbr == 0:
emit_signal("Dead", MyNbr, position)
self.queue_free()