diff --git a/flixel/FlxSprite.hx b/flixel/FlxSprite.hx index 8fc653620a..542c03145a 100644 --- a/flixel/FlxSprite.hx +++ b/flixel/FlxSprite.hx @@ -251,6 +251,13 @@ class FlxSprite extends FlxObject */ public var scale(default, null):FlxPoint; + /** + * An `FlxMatrix` that is concatenated to the internal matrix. + * Use this if you want to make unique changes to the rendering of `this` sprite. + * @since 5.9.0 + */ + public var transform(default, null):FlxMatrix; + /** * Blending modes, just like Photoshop or whatever, e.g. "multiply", "screen", etc. */ @@ -393,6 +400,7 @@ class FlxSprite extends FlxObject offset = FlxPoint.get(); origin = FlxPoint.get(); scale = FlxPoint.get(1, 1); + transform = new FlxMatrix(); _halfSize = FlxPoint.get(); _matrix = new FlxMatrix(); colorTransform = new ColorTransform(); @@ -418,6 +426,7 @@ class FlxSprite extends FlxObject offset = FlxDestroyUtil.put(offset); origin = FlxDestroyUtil.put(origin); scale = FlxDestroyUtil.put(scale); + transform = null; _halfSize = FlxDestroyUtil.put(_halfSize); _scaledOrigin = FlxDestroyUtil.put(_scaledOrigin); @@ -856,6 +865,8 @@ class FlxSprite extends FlxObject _matrix.rotateWithTrig(_cosAngle, _sinAngle); } + _matrix.concat(transform); + getScreenPosition(_point, camera).subtractPoint(offset); _point.add(origin.x, origin.y); _matrix.translate(_point.x, _point.y); @@ -1285,7 +1296,7 @@ class FlxSprite extends FlxObject if (FlxG.renderTile) return false; - return isSimpleRenderBlit(camera); + return isSimpleRenderBlit(camera) && transform.isIdentity(); } /** @@ -1704,6 +1715,7 @@ interface IFlxSprite extends IFlxBasic var offset(default, null):FlxPoint; var origin(default, null):FlxPoint; var scale(default, null):FlxPoint; + var transform(default, null):FlxMatrix; var velocity(default, null):FlxPoint; var maxVelocity(default, null):FlxPoint; var acceleration(default, null):FlxPoint; diff --git a/flixel/math/FlxMatrix.hx b/flixel/math/FlxMatrix.hx index 26c3b7c881..c70d1f6798 100644 --- a/flixel/math/FlxMatrix.hx +++ b/flixel/math/FlxMatrix.hx @@ -9,6 +9,37 @@ import openfl.geom.Matrix; */ class FlxMatrix extends Matrix { + public inline function isIdentity():Bool + { + return a == 1 && b == 0 && c == 0 && d == 1 && tx == 0 && ty == 0; + } + + /** + * Skews `this` matrix, in radians. + * @param skewX Horizontal skew in radians. + * @param skewY Vertical skew in radians. + * @return `this` skewed matrix. + */ + public inline function skewRadians(skewX:Float, skewY:Float):FlxMatrix + { + b = Math.tan(skewY); + + c = Math.tan(skewX); + + return this; + } + + /** + * Skews `this` matrix, in degrees. + * @param skewY Horizontal skew in degrees. + * @param skewX Vertical skew in degrees. + * @return `this` skewed matrix. + */ + public inline function skewDegrees(skewX:Float, skewY:Float):FlxMatrix + { + return skewRadians(skewY * FlxAngle.TO_RAD, skewX * FlxAngle.TO_RAD); + } + /** * Rotates this matrix, but takes the values of sine and cosine, * so it might be useful when you rotate multiple matrices by the same angle diff --git a/flixel/text/FlxText.hx b/flixel/text/FlxText.hx index 3378887100..7c63b8adf3 100644 --- a/flixel/text/FlxText.hx +++ b/flixel/text/FlxText.hx @@ -1056,6 +1056,8 @@ class FlxText extends FlxSprite if (angle != 0) _matrix.rotateWithTrig(_cosAngle, _sinAngle); } + + _matrix.concat(transform); // same as super but checks _graphicOffset getScreenPosition(_point, camera).subtractPoint(offset).subtractPoint(_graphicOffset);