Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

6
How to play a programmed animation once?
Post Flair (click to view more posts with a particular flair)
Post Body

Hi. I have a very simple question.

I have a Sprite (RefreshButton) that I want to rotate 360 degrees after it has been pressed. I'm detecting whether it's been clicked like so:

func _input(event):
    if event is InputEventMouseButton:
        if $RefreshButton.hovered:
            if event.button_index == BUTTON_LEFT:
                if not event.pressed: # button up
                    $RefreshButton.spin()

Now, the problem is, the only way I know how to make that animation play, is to have a _process(delta) method constantly check whether it needs to be played. Like so:

var spinning: bool = false
var rotation_speed: int = 1000

func spin():
    spinning = true

func _process(delta):
    print(spinning)
    if spinning:
        rotation_degrees  = delta * rotation_speed
        if rotation_degrees > 359:
            rotation_degrees = 0
            spinning = false

This seems very unoptimal (requires a function that constantly checks whether the animation should be played, even though we know exactly at which point it should start), and what's worse, with more animations, it makes _process(delta) method extremely bloated.

What is the proper way of achieveing this, without having a method that's constantly running in the background?

Author
Account Strength
100%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
20,647
Link Karma
10,355
Comment Karma
9,842
Profile updated: 1 day ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago