Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Area2D
- var is_selected = false setget on_is_selected
- signal area_selected
- signal area_deselected
- func _ready():
- # warning-ignore:return_value_discarded
- connect("area_deselected", self, "on_area_deselected")
- # warning-ignore:return_value_discarded
- connect("area_selected", self, "on_area_selected")
- print(name, ": ", z_index)
- func _on_Area2D_mouse_entered():
- emit_signal("area_selected", self)
- func _on_Area2D_mouse_exited():
- emit_signal("area_deselected", self)
- func on_area_selected(area: Object):
- if area == self:
- var smb_selected = false
- for a in get_overlapping_areas():
- if a.is_selected == true:
- smb_selected = true
- if not smb_selected:
- self.is_selected = true
- func on_area_deselected(area: Object):
- if area == self:
- if is_selected == true:
- self.is_selected = false
- for a in get_overlapping_areas():
- var space = get_world_2d().direct_space_state
- var mousePos = get_global_mouse_position()
- if not space.intersect_point(mousePos, 4, [], 2147483647, false, true).empty():
- print(space.intersect_point(mousePos, 4, [], 2147483647, false, true))
- for i in space.intersect_point(mousePos, 4, [], 2147483647, false, true):
- if i["collider"] == a:
- a.on_area_selected(a)
- func on_is_selected(value):
- is_selected = value
- if value == true:
- z_index += 1
- else:
- z_index -= 1
- print(name, ": ", z_index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement