I have about 100 sprites on screen, and I want to touch/click them individually, and I need to create them only using script, not with the editor.
I've tried using
TouchScreenButton
InputEventScreenTouch
Control
ColorRect
Area2D
Here is my code:
var click_dummy = ColorRect.new()
click_dummy.color = Color(0,1,0,0.2)
click_dummy.rect_size = Vector2(50,50)
click_dummy.rect_position = Vector2(pt[0]-25,pt[1]-25)
click_dummy.set_script(touchscript)
card_node.add_child(click_dummy)
click_dummy.name = 'click'+str(card_id)+'_'+str(i)
var scale = 0.7 * rng.randf_range(0.75, 1.0)
var angle = rng.randf_range(0,180)
var spr = Sprite.new()
spr.scale = Vector2(scale,scale)
spr.rotate(angle)
spr.position = Vector2(pt[0],pt[1])
spr.texture = load("res://jfsdlfhsdjo")
Here is the touchscript script:
extends ColorRect
#extends Sprite
#extends Control
#extends TouchScreenButton
func _ready():
pass
func _process(delta):
pass
#func _input_event(event):
func _input(event):
if event is InputEventScreenTouch or event is InputEventMouseButton:
# if event.is_pressed():
print(event.position)
print(get_name())
Clicking/touching fires the event on all the sprites I have, while I just want to fire the event on the one I touch/click.