Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flixel/animation/FlxAnimation.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions flixel/math/FlxMath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down