Okay phew! Slugging through it a bit more now, thanks for the post, I think I've managed to get the rect variable setup correctly, here's how my code is looking so far with the 2D box, let me know if it's the right idea, I've just taken the selection box code I found previously and plugged in the rect to a variable you can grab from elsewhere as a minimal example for people to work from.
extends Control
var isDragging = false
var dragStart = Vector2()
var dragEnd = Vector2()
var selectionBoxRect
func _physics_process(delta):
if isDragging == true:
queue_redraw()
func _unhandled_input(event):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.is_pressed():
isDragging = true
dragStart = get_global_mouse_position()
elif isDragging == true:
isDragging = false
var dragEnd = get_global_mouse_position()
queue_redraw()
func _draw():
if isDragging == true:
selectionBoxRect = Rect2 (dragStart, get_global_mouse_position() - dragStart)
draw_rect(selectionBoxRect, Color.DARK_GREEN, false, 2.0)
I'm thinking I just plug the selectionBoxRect from the control node into the selection_rect yes? Now I need to look at how to use the axis aligned bounding box too, I hadn't come across this little bit of code before, also here's how my hierarchy is looking at the moment.
