-
Notifications
You must be signed in to change notification settings - Fork 469
FlxMatrixSprite #3427
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
Open
Geokureli
wants to merge
7
commits into
HaxeFlixel:dev
Choose a base branch
from
Geokureli:matrix-sprite
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
FlxMatrixSprite #3427
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
640cf66
add matrix isIdentity skewRandians and skewDegrees
Geokureli 8bf9b54
WIP add FlxMatrixSprite
Geokureli 7e42efd
fixes
Geokureli b90e85d
D'oh
Geokureli 6d3c6c8
D'oh!
Geokureli 4498500
D'OH!
Geokureli ef895a6
omgwtf
Geokureli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package flixel.effects; | ||
|
||
import flixel.FlxSprite; | ||
import flixel.graphics.frames.FlxFrame; | ||
import flixel.math.FlxMatrix; | ||
|
||
/** | ||
* A sprite that uses a `renderMatrix` to transform its rendering | ||
*/ | ||
class FlxMatrixSprite extends FlxSprite | ||
{ | ||
/** | ||
* The matrix used to transform how this sprite is rendered | ||
* | ||
* @since 6.2.0 | ||
*/ | ||
public final renderMatrix:FlxMatrix; | ||
|
||
public function new (x = 0.0, y = 0.0, ?simpleGraphic) | ||
{ | ||
renderMatrix = new FlxMatrix(); | ||
|
||
super(x, y, simpleGraphic); | ||
} | ||
|
||
override function isSimpleRenderBlit(?cam) | ||
{ | ||
return super.isSimpleRenderBlit(cam) || renderMatrix.isIdentity(); | ||
} | ||
|
||
override function prepareComplexMatrix(matrix:FlxMatrix, frame:FlxFrame, camera:FlxCamera) | ||
{ | ||
frame.prepareMatrix(matrix, FlxFrameAngle.ANGLE_0, checkFlipX(), checkFlipY()); | ||
matrix.translate(-origin.x, -origin.y); | ||
matrix.scale(scale.x, scale.y); | ||
|
||
if (bakedRotationAngle <= 0) | ||
{ | ||
updateTrig(); | ||
|
||
if (angle != 0) | ||
matrix.rotateWithTrig(_cosAngle, _sinAngle); | ||
} | ||
|
||
matrix.concat(renderMatrix); | ||
|
||
final screenPos = getScreenPosition(camera).subtract(offset); | ||
screenPos.add(origin.x, origin.y); | ||
matrix.translate(screenPos.x, screenPos.y); | ||
screenPos.put(); | ||
|
||
if (isPixelPerfectRender(camera)) | ||
{ | ||
matrix.tx = Math.floor(matrix.tx); | ||
matrix.ty = Math.floor(matrix.ty); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are flipped
Suggested change
|
||||||
} | ||||||
|
||||||
/** | ||||||
* 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 | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@DetectiveBaldi these are flipped too, right?
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.
From what I can tell this is intended as intended, the same behavior can be seen in the original
FlxSkewedSprite
class: