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 clipRect support #2051

Merged
merged 4 commits into from
Apr 27, 2017
Merged

FlxSpriteGroup clipRect support #2051

merged 4 commits into from
Apr 27, 2017

Conversation

MSGhero
Copy link
Member

@MSGhero MSGhero commented Apr 18, 2017

Needs more extensive (unit) testing, but the basics are done. Essential for haxeui components.

Suggestions welcome.

@@ -879,6 +890,10 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
private inline function originTransform(Sprite:FlxSprite, Origin:FlxPoint) Sprite.origin.copyFrom(Origin);
private inline function scaleTransform(Sprite:FlxSprite, Scale:FlxPoint) Sprite.scale.copyFrom(Scale);
private inline function scrollFactorTransform(Sprite:FlxSprite, ScrollFactor:FlxPoint) Sprite.scrollFactor.copyFrom(ScrollFactor);
private inline function clipRectTransform(Sprite:FlxSprite, ClipRect:FlxRect) {
Copy link
Member Author

Choose a reason for hiding this comment

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

For the record, I don't like this part

Copy link
Member

Choose a reason for hiding this comment

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

"This part"? Isn't this bascially the whole PR? :D

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like how it looks so different from the others

Copy link
Member Author

Choose a reason for hiding this comment

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

Aside from the inlined curly brace...

@@ -280,6 +281,9 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
sprite.alpha *= alpha;
sprite.scrollFactor.copyFrom(scrollFactor);
sprite.cameras = _cameras; // _cameras instead of cameras because get_cameras() will not return null

if (clipRect != null) clipRectTransform(sprite, clipRect);
else sprite.clipRect = null;
Copy link
Member

Choose a reason for hiding this comment

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

This seems to make this a breaking change, because it removes the clipRect that sprite might have had before being added. Not sure that's a good idea?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess the alternative would be to merge the parent's clip and the child's clip together. I'd have to look at that in Flash to see how it works. Either way, the child's clip would change, though.

Copy link
Member

Choose a reason for hiding this comment

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

This is the case where the parent's clipRect is null though, so there isn't really anything to merge?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess the "merge" would be null + child.clip which results in child.clip. Was your initial comment about line 286 or both of those lines?

Copy link
Member

Choose a reason for hiding this comment

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

Just line 286.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah not sure why that line was there, removed.

@Gama11 Gama11 changed the title [WIP] Sprite group clipRect [WIP] FlxSpriteGroup clipRect support Apr 26, 2017
@Gama11
Copy link
Member

Gama11 commented Apr 26, 2017

The [WIP] is supposed to indicate you don't want this to be merged yet?

@MSGhero
Copy link
Member Author

MSGhero commented Apr 26, 2017

What I have works, but idk if I should add more to it or if it's correct.

+ remove unnecessary line
@MSGhero MSGhero changed the title [WIP] FlxSpriteGroup clipRect support FlxSpriteGroup clipRect support Apr 26, 2017
@@ -280,6 +281,8 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
sprite.alpha *= alpha;
sprite.scrollFactor.copyFrom(scrollFactor);
sprite.cameras = _cameras; // _cameras instead of cameras because get_cameras() will not return null

if (clipRect != null) clipRectTransform(sprite, clipRect);
Copy link
Member

Choose a reason for hiding this comment

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

This null check now seems unnecessary, since clipRectTransform() can handle null?

Copy link
Member Author

@MSGhero MSGhero Apr 26, 2017

Choose a reason for hiding this comment

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

You're right, that's some leftover code from when I was testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually no, that would override the child's existing clip. The transform sets the child's clip based on the parent's, so you'd be setting null instead of leaving the existing one alone.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, you're right!

Great thing to unit-test. ;)

@Gama11
Copy link
Member

Gama11 commented Apr 26, 2017

Needs more extensive (unit) testing [...]

So are you still planning to write some tests for this?

@MSGhero
Copy link
Member Author

MSGhero commented Apr 26, 2017

I guess I'll write some tests 😜

@MSGhero
Copy link
Member Author

MSGhero commented Apr 26, 2017

Kind of a weird test, but it covers the 3 cases: existing child clip, nonexisting child clip, and nonexisting parent clip.

@Gama11
Copy link
Member

Gama11 commented Apr 27, 2017

Thanks!

I still hate how clipRects have to be re-assigned entirely for changes to be registered, but that doesn't really have anything to do with this PR...

@Gama11 Gama11 merged commit 9939ee1 into HaxeFlixel:dev Apr 27, 2017
@MSGhero
Copy link
Member Author

MSGhero commented Apr 27, 2017

I don't think anyone likes that...

@Gama11
Copy link
Member

Gama11 commented Apr 27, 2017

Just occured to me, do we need to take offset into account?

@MSGhero
Copy link
Member Author

MSGhero commented Apr 27, 2017

I want to say no, but I'll check.

@MSGhero
Copy link
Member Author

MSGhero commented Apr 27, 2017

As it is now, it matches the behavior of a FlxSprite's clip+offset, where it clips first and offsets second (i.e. the offset doesn't affect where the clip occurs).

One thing I noticed is that the parent's offset doesn't get copied to the child in preAdd(). Should it?

@MSGhero MSGhero deleted the clip-kids branch April 29, 2017 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants