0 votes

I've been working on a card game where, like most card games, players have a hand with cards and a board where you can place cards on.

In this game, the board can expand a lot (e.g. if users keep on placing cards to the left). To make the UI more friendly, users can zoom in and out as well as pan the camera in any direction.

Originally the game was written completely with Node2D derived elements. I decided to start rewriting part of it using control nodes since now the hand can be handled easier, since cards can just go into a horizontal scroll box, drag and drop can be implemented through the engine (via drop_data and get_drag_data), and just in general a lot of hand written code can be replaced with native Control code.

I figured the whole game is effectively a menu, so implementing it in control nodes seemed like a good idea.

So far it's mostly gone smoothly but I am having a couple of issues. It seems when I pan the camera (I'm using a custom camera) the dragged items preview won't be under the mouse, but instead offset relative to how far I've moved the camera.

This got me thinking, that I'm mixing Node2D derived elements like the camera and control derived elements in the same scene tree. Is this a good idea, or is this not really how it's supposed to be done?


This isn't part of the question, but if anyone is wondering how that drag and drop issue came around, you can reproduce it by creating a scene like the following:

  • Node2D

    • Camera2D (set as active camera)
    • CenterContainer

      • Sprite (give it an image)

Then just adding this function to the CenterContainer script:

func get_drag_data(_pos):
    set_drag_preview(duplicate())
    return self

Now when you try to drag the CenterContainer, you will see the preview is very far away from the mouse. If you delete the Camera, the preview will be centered on the mouse

asked Jul 23 in Engine by Keeyan (12 points)

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 How to use this Q&A? before posting your first questions.