Created
July 28, 2018 19:28
-
-
Save Beelzenef/a98a148d37d6b66c60b8c50b2b300fad to your computer and use it in GitHub Desktop.
selection box for top-down 2D game in Godot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Control | |
var initialPos | |
var currentPos | |
func _ready(true): | |
set_process(true) | |
func _process(delta): | |
createBox() | |
func createBox(): | |
if Input.is_action_pressed("ui_left_mouse_button"): | |
initialPos = get_global_mouse_position() | |
rectd.set_begin(initialPos) | |
if Input.is_action_pressed("ui_left_mouse_button"): | |
currentPos = get_global_mouse_position() | |
rectd.set_begin(Vector2(min(initialPos.x, currentPos.x), min(initialPos.y, currentPos.y))) | |
rectd.set_end(Vector2(max(initialPos.x, currentPos.x), max(initialPos.y, currentPos.y))) | |
if Input.is_action_just_released("ui_left_mouse_button"): | |
rectd.set_begin(Vector2(0, 0)) | |
rectd.set_end(Vector2(0, 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment