[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flipped_horizontally and flipped_vertically signals for Sprite2D, AnimatedSprite2D and SpriteBase3D #99634

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Lazy-Rabbit-2001
Copy link
Contributor
@Lazy-Rabbit-2001 Lazy-Rabbit-2001 commented Nov 24, 2024

Completes: godotengine/godot-proposals#5146

In that proposal, the author noted mentioned the following:

Implement a AnimatedSprite.frame_refreshed signal. Although the signal is reasonably self-explanatory, It will be emitted only once per frame, if one of the following happen:

The animation changes;
The frame changes;
flip_x and flip_y are toggled;
The SpriteFrames frames is changed;

According to the reference, the frame_refreshed will be emitted on the change of flip_*. But sadly, the signal was obsolescent.

Meanwhile, there has been a lot of discussions and proposal duplicates about complaining getting unexpected result from a scale like (-1, 1) and the users wanted to figure out a way to the solution and put their hope on flip_*. Because we don't have property_changed signal for Object, which could be costly for the performance, I implemented a pair of signals for some nodes such as Sprite2D, AnimatedSprite2D and SpriteBase3D that have members beginning with flip_, which will be emitted on the change of these members.

By connecting this signal to other sprites, one can easily achieve the flipping synchronization and safe reflection on single axis (negative X/Y scale without polluting the global rotation):

# Taking a Sprite2D as an example
extends Sprite2D

func _ready() -> void:
    (get_parent() as Sprite2D).flipped_horizontally.connected(
        func _on_parent_flipped_horizontally(flipped: bool) -> void:
            if flip_h == flipped:
               return
            flip_h = flipped
            position.x *= -1.0
    )

@AThousandShips AThousandShips changed the title Added flipped_horizontally and flipped_vertically signals for Sprite2D, AnimatedSprite2D and SpriteBase3D Add flipped_horizontally and flipped_vertically signals for Sprite2D, AnimatedSprite2D and SpriteBase3D Nov 24, 2024
@Mickeon Mickeon added this to the 4.x milestone Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants