+1 vote

I want to make a simple jigsaw puzzle game.
Should I make pieces of the puzzle Area2Ds? Then allow the player to move the Area2Ds in process function till the pieces reach a certain Vector2D position?
Will this work?

in Engine by (100 points)

I don't have an example to show you, but assuming it's a jigsaw with regular shapes I'd make the "board" a grid container of size X * Y (where X is the number of columns and Y the number of rows). Then you drag and drop pieces onto the grid and the grid takes care of lining them up.

For a drag and drop function, look at this: https://kidscancode.org/godot_recipes/physics/rigidbody_drag_drop/

Thanks. This a great answer.
Do you need a rigidbody for this? How will the piece that needs to go beneath a cell reach its place? This will force the player to start with the bottom most row in the Grid first, and then work upwards.
Is there an example where one can pick up and drop a Sprite?
Thanks in advance.

Hi Bernard,
I tried to replicate the code in kidscancode.org with Sprites. However, I haven't being able to invoke the drop function there. I've just separated the pickup and drop with a call to yield(), which not very useful.
I am not able to invoke the input-event function.
Other thing is that I am not able to see all the 3 Sprites (which are child nodes of World) during runtime. Only, one shows up during runtime. The Sprites are not instances, though. Is that the problem? Here is the code of my World and Ball script:

extends Sprite
signal clicked

var held = true

func _process(delta):

func drop_in_Grid():
    while held:
        global_transform.origin = get_global_mouse_position()
        yield(get_tree().create_timer(1), "timeout")
    held = false

func _input_event(viewport, event, shape_idx):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT and event.pressed:

            emit_signal("clicked", self)

extends Node2D

var held_object = null

func _ready():
    for node in get_tree().get_nodes_in_group("pickable"):
        node.connect("clicked", self, "_on_pickable_clicked")

func _on_pickable_clicked(object):
    if !held_object:
        held_object = object

func _unhandled_input(event):
    if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
        if held_object and !event.pressed:
            held_object = null

Node Hierarchy

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.