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

FlxButton labels don't work when moves is false - Update label position on status change #3232

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

Itz-Miles
Copy link
Contributor

Hello contributors, It'z Miles!

But that's enough about me. I'm here to patch up a problem with the labels on FlxButtons.

The FlxButton's label is being repositioned. Every. Single. Frame.

The setter for x and y are responsible for repositioning the FlxButton's label. FlxObject updateMotion() is updating the position and physics, which means it constantly repositions the label regardless of whether the button has moved or not!

For a commonly static UI element, it makes sense for moves to be false.

FlxButtons (that generally don't move) can turn it off and skip the physics calculations, therefore repositioning the label only when we need it to. The small change I've introduced makes the label update whenever the state changes!

Pros of calling updateLabelPosition() on a state change:

  • It happens only whenever the button is interacted with.
  • It doesn't introduce any breaking changes.
  • The button's label now works when moves is false.
  • The constant performance gains when moves is false are astronomical.
  • The occasional performance impact when moves is true is negligible and sparse.

Miles out! Feel free to suggest further improvements.

@Itz-Miles
Copy link
Contributor Author

A good follow-up would be to set FlxButton's moves to false by default (much like scrollfactor 0), but it would be a breaking change because older flixel projects may have moving buttons that don't explicitly state moves.

@Geokureli
Copy link
Member

Geokureli commented Aug 14, 2024

I'm having trouble seeing where moves = false actually prevents the label from moving, can you shed some light on that?

I don't see moves or updateMotion referenced anywhere

Edit: NVM, found it

@Geokureli Geokureli merged commit 7acac91 into HaxeFlixel:dev Aug 15, 2024
11 checks passed
@Geokureli
Copy link
Member

Thanks!

@Geokureli Geokureli added this to the 5.9.0 milestone Aug 15, 2024
@Itz-Miles Itz-Miles deleted the flxbutton-label-status branch August 15, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants