|Topic was automatically imported from the old Question2Answer platform.
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
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:
- Camera2D (set as active camera)
- Sprite (give it an image)
Then just adding this function to the CenterContainer script:
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