Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lava_goose |
Hello
I’m completely now to Godot and I try to create a simple project there you have few targets on the window and whenever you click on one, it will dissapear. The placement of each target is randomly chosen.
Here is my code:
Main:
extends Node
export (PackedScene) var Aim
var aim_mob
var mob_list
var screenSize
var rng = RandomNumberGenerator.new()
var rndX
var rndY
# Called when the node enters the scene tree for the first time.
func _ready():
screenSize = get_viewport().get_visible_rect().size
initialize_mobs(5)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func initialize_mobs(number : int):
for x in range(number):
rng.randomize()
rndX = rng.randi_range(0, screenSize.x)
rndY = rng.randi_range(0, screenSize.y)
aim_mob = Aim.instance()
add_child(aim_mob)
aim_mob.position = Vector2(rndX, rndY)
func _on_Aim_clicked():
aim_mob.on_click()
Aim:
extends Area2D
var score = 0
signal clicked
func _ready():
pass
func _input_event(viewport, event, shape_idx):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.is_pressed():
emit_signal("clicked")
func on_click():
self.visible = !self.visible
So right now when I click on one specific target, one completely different disappear.
My questions are:
- How I would make program to “know” that one target that I clicked
should disappear? - How can I use object’s method on specific instance of this object?
Is input_event
connected? Also the “Clicked” signal isn’t doing anything unless another node is waiting for that signal with a yield.
Magso | 2020-07-01 12:53