system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
Incognito |
extends Area2D
var position_draw = Vector2(200, 100)
var _can_click = false
func _ready():
var a = Sprite.new()
a.name = "test_sprite"
a.texture = load("res://img/120px-Roundel_of_El_Salvador.svg.png")
a.position = position_draw
self.add_child(a, true)
var coll = CollisionShape2D.new()
coll.name = "test_collision"
var circle = CircleShape2D.new()
circle.radius = 200
coll.shape = circle
coll.position = position_draw
self.add_child_below_node($test_sprite, coll, true)
print(self.print_tree_pretty())
#┖╴Area2D
# ┠╴test_sprite
# ┖╴test_collision
#Null
self.connect("mouse_entered", self, "_on_Area2D_mouse_entered")
#working?
self.connect("mouse_exited", self, "_on_Area_2D_mouse_exited")
#working?
func _on_Area2D_mouse_entered():
_can_click = true #Not work
func _on_Area2D_mouse_exited():
_can_click = false #Not work
func _click_check():
if _can_click:
if Input.is_action_pressed("click"):
print('Click') #Not work
func _process(_delta):
_click_check()
system
2
|
|
|
|
Reply From: |
jgodfrey |
The above code works fine for me except that you have a typo in your signal name here:
self.connect("mouse_exited", self, "_on_Area_2D_mouse_exited
That should be _on_Area2D_mouse_exited
to match your function name.
Thank you, you helped me understand the problem.
Tell me why everything works like this:
┖╴Node2D
┖╴Area2D
┠╴test_sprite
┖╴test_collision
That’s how the script Area2D breaks:
┖╴Node2D
┠╴ColorRect #Background
┖╴Area2D
┠╴test_sprite
┖╴test_collision
How can I fix this so that I can add other nodes and the script Area2D doesn’t break?
Incognito | 2022-11-29 05:50