FlxButton
labels don't work when moves
is false - Update label position on status change
#3232
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:moves
is false.moves
is false are astronomical.moves
is true is negligible and sparse.Miles out! Feel free to suggest further improvements.