Hi, I am making a point and click game and I need some directions on making an area2d as a hotspot:
The area2d configuration is as follows:
Area2D (ObjTemplate) (no script)
->Sprite
->CollisionShape2D (no collision set)
At this time in my program, I can get a JSON file with various x,y, hotspot-x, hotspot-y and images and setup custom made area2d based on a preloaded template of above file.
What I am trying to do is attach a script that has an _input() function and try to use this as a hotspot click:
for object in objects:
var tmp = ObjTemplate.instance()
tmp.get_node("sprite").texture = object.image
tmp.position(object.x, object.y)
var shape = RectangleShape2D.new()
tmp.get_node("CollisionShape2D").shape = shape
shape.extents = Vector2(object.hs_x / 2, object.hs_y / 2)
tmp.get_node(".").set_script = load("res://game_assets/"+object.script+".gd")
add_node(tmp)
Assume object.script is Lobby, so in Lobby.gd I have the following:
extends Area2D
var count = 0
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if event.pressed:
count += 1
print("Click:" + str(count))
I don't get any errors during runtime, but I don't get any _input interactions either. If I attach the script directly to ObJTemplate then it will work.
So, does it need anything to "refresh" or enable the contents of Lobby.gd somehow to be parsed and interpreted at runtime?