0 votes

So that a mouse click on my screen trigger an animation at the end of the timer?
Cheers!

in Engine by (325 points)

1 Answer

0 votes

1.) add a timer called "MouseTimer" to your game.
2.) set a wait time for "MouseTimer" (5 secs), override that in code
3.) set the "MouseTimer" to "one shot"
4.) connect the "MouseTimer" "timeout()" signal to your game script
5.) create an animation for Node (I assumed Player) called "MouseTimer"
6.) add code to play that animation in "timeout()" signal in game script

(See code below)

func _input(event):
    if InputEventMouseButton: # Triggers on any mouse button
        $MouseTimer.wait_time = 2 # Override wait time (in Secs)
        $MouseTimer.start() # Start Timer

func _on_MouseTimer_timeout():
    #print("MouseTimer Finished") # testing mouse timer
    $Player/AnimationPlayer.current_animation = "MouseTimer" # set current animation

If you want a use a specific mouse button, just add code after if InputEventMouseButton: Oh and I am assuming you are using Godot3

Hope this helps :-)

by (204 points)

Thxs, but actually I want an animation or a label to be triggered by a mouse click when the timer is out. Not to start the timer eh?
Something like:

func _on_Timer_timeout():
if InputEventMouseButton: 
$Hmm/Label.start() or $("AnimationPlayer").play("exemple")

Here the trouble is, the event is unindentified, and I don't know how set it in that timer func.
And yes, usin Godot 3. :)

So are you,
1.) asking to trigger a mouse click when the timer times out? which in turn triggers an animation
2.) or are you saying that when a timer times out you want the user to trigger the animation on a mouse click, but only if the timer has expired?

Assuming its #2 Just set a flag in the Timer timeout signal and then add it as a "and" to your if statement somewhere else, like func _input(event).

extends Node

var timer_expired

func _ready():
    pass

func _on_Timer_timeout():
     timer_expired = true

func _input(event):
     if InputEventMouseButton and timer_expired:
          $Hmm/Label.start() or $("AnimationPlayer").play("example")

That's it! Cheers for you!

Don't forget to set timer_expired back to false after the triggered event :-)

Yep, done. Thxs again! :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.