Hi there, I’m trying to create a small drawing function where the player can hover their mouse over a small UI panel which will then expand and allow them to draw within the panel like a canvas. When the user exits the panel it shrinks back down to its original size and keeps the image within the canvas. At the moment I don’t understand why when the panel moves from its original position, the lines created become very skewed and don’t stay with the original parent. If this problem is solved I can then place the panel wherever it needs to go on the player UI without further issues.
That’s correct, however I don’t believe it’s the influencing factor, when the drawing panel is positioned at the origin (0,0) it works as intended. As soon as I move the drawing panel away from the origin, the problem occurs. I like having the lines as children of the panel because it means that they can scale at the same time as the panel and in the same direction. Any other workarounds I’m happy to try.
When debugging I found that the panel’s position and global position were the same however the line’s position and global position were different. As the line is being added as a child of the panel it’s position of origin is the corner of the panel wherever that may be in the scene while the global position remains the same as the panel.
To solve this I added this line of code which moves the position of the line back to the origin by subtracting the global position of the line (the same value as the position of the panel). This allows the lines to be drawn inside the box no matter where the box is relative to the origin.
Please also note that the “Lines” container is at 0.5 scale as the children Line2D will be scaled at the same time as the panel.