diff --git a/flixel/animation/FlxAnimation.hx b/flixel/animation/FlxAnimation.hx index a49c91f94c..006234d78f 100644 --- a/flixel/animation/FlxAnimation.hx +++ b/flixel/animation/FlxAnimation.hx @@ -177,7 +177,7 @@ class FlxAnimation extends FlxBaseAnimation reversed = Reversed; paused = false; - _frameTimer = 0; + _frameTimer = -FlxG.elapsed / 2; finished = frameDuration == 0; var maxFrameIndex:Int = numFrames - 1; diff --git a/flixel/math/FlxMath.hx b/flixel/math/FlxMath.hx index b0c579e4d9..5ed9cf553d 100644 --- a/flixel/math/FlxMath.hx +++ b/flixel/math/FlxMath.hx @@ -548,6 +548,43 @@ class FlxMath return fastSin(n + 1.570796327); // sin and cos are the same, offset by pi/2 } + /** + * ~1.3x faster than calling fastSin() + fastCos() separately. + */ + public static inline function fastSinCos(angle:Float):{sin:Float, cos:Float} + { + var n = angle * 0.3183098862; + + if (n > 1) + { + n -= (Math.ceil(n) >> 1) << 1; + } + else if (n < -1) + { + n += (Math.ceil(-n) >> 1) << 1; + } + + var sin:Float; + if (n > 0) + { + sin = n * (3.1 + n * (0.5 + n * (-7.2 + n * 3.6))); + } + else + { + sin = n * (3.1 - n * (0.5 + n * (7.2 + n * 3.6))); + } + + var cos = Math.sqrt(1 - sin * sin); + + var originalN = n * Math.PI; + if (originalN < -Math.PI * 0.5 || originalN > Math.PI * 0.5) + { + cos = -cos; + } + + return {sin: sin, cos: cos}; + } + /** * Hyperbolic sine. */