Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | fungaim |
Hi folks, I am trying to make my buttons jiggle after being pressed, and then after like 2 seconds then it would change the scene. What I am struggling with is what I think is the lack of a native time function. So I created a timer function as a global (since I would like to reuse the delay code in many buttons etc) but I am having an issue in which the timer code doesn’t trigger the chance scene code. If I place the timer contents directly into the button it works but if I try to make it a function that is hosted globally it doesnt. The function does get triggered but it does not call the action for the timer.
in global snippets:
extends Node
func _delay(delay,action):
print("delay triggered")
print(action)
var timer = Timer.new()
timer.set_wait_time(delay)
timer.set_one_shot(true)
timer.connect("timeout", self, action)
add_child(timer)
return timer.start()
In button pressed:
func _switch_delay():
BackSwitcher.switch_scene("res://scenes/jumble/jumble_menu_screen.tscn")
pass
func _on_jumble_play_button_pressed():
self.rect_scale.x = 0.2 + deg2rad(sin(2*time + 1))/2
self.rect_scale.y = 0.2 + deg2rad(sin(2*time + 1))/2
self.rect_position.x = start_x + ((self.rect_size.x * 0.2) - (self.rect_size.x * self.rect_scale.x))/2
self.rect_position.y = start_y + ((self.rect_size.y * 0.2) - (self.rect_size.y * self.rect_scale.y))/2
self.rect_rotation = 0 + deg2rad(sin(10*time + 15))
snippets._delay(5.0,_switch_delay())