Add a node (sprite) on screen after mouse click, on mouse coordinates ?

fkossyvasfkossyvas Posts: 7Member

Hi, i am starting just now studying Godot but i cannot understand how can i do this :
i want to add an object on screen (from what i understand, i have to instantiate it), just where i click the left mouse button (place it at coordinated of mouse click).
What should be the best way to do it ?
Thank you in advance.


  • AvencherusAvencherus Posts: 49Member
    edited February 2017 Answer ✓

    The best way depends on your situation, but here is a basic example.

    extends Node2D
    func _ready():
    func _input(event):
        if(event.type == InputEvent.MOUSE_BUTTON and event.button_index == BUTTON_LEFT and event.pressed):
            var sprite =
  • fkossyvasfkossyvas Posts: 7Member

    Thank you, i will try it right away !

  • AvencherusAvencherus Posts: 49Member
    Answer ✓

    No problem.

Sign In or Register to comment.