diff --git a/scripts/perk_card.gd b/scripts/perk_card.gd index ef5454c..d331031 100644 --- a/scripts/perk_card.gd +++ b/scripts/perk_card.gd @@ -5,7 +5,9 @@ var play_sound: Callable var _recipe_panel: Control = null var _panel_tween: Tween = null -var _hover_tween: Tween = null +var _hover_active: bool = false +var _hover_rest_y: float = 0.0 +var _hover_phase: float = 0.0 const _PANEL_REST_Y = 18 const _FRUIT_ATLAS = preload("res://assets/16x16 Pixelart Food Icons/Pixel_Foods(ARTLİNE).png") @@ -132,6 +134,12 @@ func _on_button_down() -> void: on_select.call() +func _process(delta: float) -> void: + if _hover_active: + _hover_phase += delta + position.y = _hover_rest_y + sin(_hover_phase * TAU / 4.0) * 3.5 + + func animate_in(): await get_tree().process_frame pivot_offset = size / 2 @@ -143,17 +151,14 @@ func animate_in(): await tween.finished if not is_instance_valid(self): return - var rest_y = position.y - await get_tree().create_timer(randf_range(0.0, 1.5)).timeout - if not is_instance_valid(self): - return - _hover_tween = create_tween().set_loops() - _hover_tween.tween_method(func(t: float): position.y = rest_y + sin(t * TAU) * 5.0, 0.0, 1.0, 4.0) + _hover_rest_y = position.y + _hover_phase = randf_range(0.0, 4.0) + _hover_active = true func animate_out(): - if _hover_tween: - _hover_tween.kill() + _hover_active = false + position.y = _hover_rest_y var start_y = global_position.y var end_y = global_position.y - 500 global_position.y = start_y