Skip to content
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

FlxSpriteGroup: setting origin should cause members to pivot around the same point #2981

Merged
merged 2 commits into from
Dec 15, 2023
Merged
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/group/FlxSpriteGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
Sprite.offset.copyFrom(Offset);

inline function originTransform(Sprite:FlxSprite, Origin:FlxPoint)
Sprite.origin.copyFrom(Origin);
Sprite.origin.set(x + origin.x - Sprite.x, y + origin.y - Sprite.y);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this behave "intuitively" if the entire group is moved? I'm not in a spot to test it myself, but it feels like there still may be weirdness if you set origin -> move group -> scale.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified my test program - a little robot holding a brick - the robot and the brick are separate sprites in the same group. I can scale the group, drive it about, rotate and scale up and down and move again. All looks ok.


inline function scaleTransform(Sprite:FlxSprite, Scale:FlxPoint)
Sprite.scale.copyFrom(Scale);
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/src/flixel/group/FlxSpriteGroupTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ class FlxSpriteGroupTest extends FlxTest
Assert.isFalse(member2.revived);
return group;
}
@Test
/**
* Ensure that member origins are correctly set when
* the group origin is set.
*/
function testOriginTransform()
{
var f1 = new FlxSprite(-10, 100);
var f2 = new FlxSprite(50, 50);
group.add(f1);
group.add(f2);

group.setPosition(280, 300);
group.origin.set(300, 400);

// Verify positions are updated - absolute
Assert.areEqual(270, f1.x);
Assert.areEqual(400, f1.y);
Assert.areEqual(330, f2.x);
Assert.areEqual(350, f2.y);

// Verify origins are correct - relative
Assert.areEqual(310, f1.origin.x);
Assert.areEqual(300, f1.origin.y);
Assert.areEqual(250, f2.origin.x);
Assert.areEqual(350, f2.origin.y);
}
}

class Member extends FlxSprite
Expand Down
Loading