-
Notifications
You must be signed in to change notification settings - Fork 435
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 FlxTween.shake
for sprite shaking.
#2549
Conversation
yes |
flixel/tweens/misc/ShakeTween.hx
Outdated
if (axes != Y) | ||
sprite.x = initialXY.x + FlxG.random.float(-intensity * sprite.width, intensity * sprite.width); | ||
if (axes != X) | ||
sprite.y = initialXY.y + FlxG.random.float(-intensity * sprite.height, intensity * sprite.height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than storing the initial x and y, I'm wondering if it should store the sprite's offset, and use the offset to shake it. this would allow it to shake objects in motion.
Also initialXY
doesn't fit the name scheme, it should be initialPosition or (if changed) initialOffset
If this tween is cancelled will it be reverted back to its original position, or the position it was shaken to? I'd prefer the former. We should add unit tests that check both, and perhaps other test are in order. Tests can be added here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you have a good argument against it, this should use sprite.offset rather than the position directly. this will also ensure that the shake effect doesn't interfere with collision bounds and is a purely graphical effect.
WIth that, renaming initialXY, and a unit test that ensures offset is properly reset on complete and cancel, this should be good to go
Now as soon as I have some time (probably at the weekend) I will start to make the changes in the code and the tests to check that it works well. |
Also fixes on completion/canceling tween.
I have tried to run the unit test but I am not very familiar with it yet. Other than that, I've been testing it on a new project to see if it actually works correctly when finalizing and/or canceling the tween and I haven't seen any problems with either. |
For some reason I'm not seeing utnit test outcomes in github actions, so I checked yours locally and it looks good. Thanks for this! P.S.: I'm making a change to FlxAxes in another branch, so you'll see a similar change to ShakeTween, from me, pretty soon |
this got added right? i cant use it |
Its not released yet, youll need to use |
Implement the same function that exists in
FlxCamera
to be used on an individualFlxSprite
(and not on the whole screen).Same as #2548 but now from FlxTween:
(I did it based on the tweens that are already made to work the same way)
Here two examples:
1.mp4
2.mp4