ataugeron / SpriteKit-Spring

SpriteKit API reproducing UIView's spring animations with SKAction
Apache License 2.0
249 stars 32 forks source link

Calculate distance correctly for animations using byValue #14

Open noahsark769 opened 7 years ago

noahsark769 commented 7 years ago

Hey! Awesome library, thanks for building it. I noticed that there's a bug with animations that use byValue, e.g.:

SKAction.scale(by:duration:delay:usingSpringWithDamping:initialSpringVelocity:)

The distance isn't calculated correctly, so the behavior uses byValue as the distance.

For example, say there's a node with a current scale of 1.0 - if we tried to scale it by 1.2, SpriteKit-Spring will currently scale it to 1.0 + 1.2 instead of 1.0 * 1.2, which in this case would more than double the scale instead of scaling appropariately. I put up an example app at https://github.com/noahsark769/NGSpriteKitSpringTest to demonstrate this.

The fix is to calculate the initialDistance based on multiplying it by initialValue.

Let me know if I need to do anything else to fix this bug! Thanks!

noahsark769 commented 7 years ago

@ataugeron bump! Would be awesome to get this out and pushed as a new version of the cocoapod 👍