class_name DieIcon extends Control ## A three-pip die face. Tumbles while `spinning` is on. var color: Color = Style.BRASS var spinning: bool = false: set(value): spinning = value if not value: _angle = 0.0 set_process(value) queue_redraw() var _angle: float = 0.0 var _frame: StyleBoxFlat func _init() -> void: custom_minimum_size = Vector2(20, 20) size = custom_minimum_size mouse_filter = MOUSE_FILTER_IGNORE _frame = StyleBoxFlat.new() _frame.draw_center = false _frame.set_border_width_all(2) _frame.set_corner_radius_all(3) _frame.anti_aliasing = true set_process(false) func _ready() -> void: # Godot turns processing on for nodes with _process when they become ready. set_process(spinning) func _process(delta: float) -> void: _angle = fmod(_angle + delta * TAU * 2.0, TAU) queue_redraw() func _draw() -> void: draw_set_transform(size / 2.0, _angle) _frame.border_color = color draw_style_box(_frame, Rect2(-7.5, -7.5, 15, 15)) for p in [Vector2(-3, -3), Vector2(0, 0), Vector2(3, 3)]: draw_circle(p, 1.45, color) draw_set_transform(Vector2.ZERO)