So, I’m creatin my ColorRect object, then I’m rotatin it and then my mous clicks are not workin. I guess, I should somehow update rect’s position. I know I can use RotationMatrix for this, but, it’s not workin also. My code:
extends Node2D
var color_rect: ColorRect = null
func _ready():
color_rect = ColorRect.new()
color_rect.color = Color.red
color_rect.rect_size = Vector2(100, 100)
color_rect.rect_position = Vector2(200, 200)
# choose some rotation point not inside our rect:
var rect_pivot_vec: Vector2 = Vector2(500, 500)
color_rect.rect_pivot_offset = rect_pivot_vec
add_child(color_rect)
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
var mouse_pos: Vector2 = event.position
if color_rect.get_rect().has_point(mouse_pos):
print("clicked on rect!")
func _physics_process(delta):
var deg = color_rect.get_rotation_degrees()
if deg < 45:
color_rect.rect_rotation += 20 * delta