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

Add "flipX / flipY" property to animations #1670

Merged
merged 6 commits into from
Dec 8, 2015

Conversation

larsiusprime
Copy link
Member

...and also make it interact properly with FlxSprite's own flipX / flipY.

Rationale: for games with big sprite sheets, it can save a lot of memory to re-use frames in animations by vertically flipping them. So if I can re-use a walk cycle and just tell it to flip the frames right in the animation call, that's extremely convenient. Much easier to do than messing around with individual frames in the atlas.

Before this pull, we have had the ability to apply flipX/flipY to individual flxFrames (such as those loaded from an atlas) -- so this means the user can now set flipX/flipY in three places:

  1. On the sprite itself
  2. On an individual frame (e.g. tagging the metadata as part of atlas loading)
  3. On an individual animation

The effect should cascade properly. So you can have a particular frame in an animation that has flipX=true, used in an animation that has flipX=true, and then the sprite itself has flipX=true, which will resolve to true because (true XOR true XOR true) == true.

@larsiusprime
Copy link
Member Author

I tried that first, but it's only a numeric operator, not a boolean. There's no boolean xor.

@Gama11
Copy link
Member

Gama11 commented Dec 4, 2015

You could also just use a != b. ;)

if (!doFlipX && !doFlipY && _frame.type == FlxFrameType.REGULAR)
{
framePixels = _frame.paint(framePixels, _flashPointZero, false, true);
}
else
{
framePixels = _frame.paintRotatedAndFlipped(framePixels, _flashPointZero, FlxFrameAngle.ANGLE_0, flipX, flipY, false, true);
framePixels = _frame.paintRotatedAndFlipped(framePixels, _flashPointZero, FlxFrameAngle.ANGLE_0, checkFlipX(), checkFlipY(), false, true);
Copy link
Member

Choose a reason for hiding this comment

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

Why call the check functions again here when the results are locally cached a few lines earlier in doFlipX / Y?

@larsiusprime
Copy link
Member Author

Ah, you're right. Well in any case the logic as it stands now is what I actually intend.

@Gama11
Copy link
Member

Gama11 commented Dec 4, 2015

Ah. Well, in that case, I'd prefer the original approach, since doing it this way introduces some redundancy. :P

@larsiusprime
Copy link
Member Author

To be clear, this is what you mean?

    private inline function checkFlipX():Bool
    {
        var doFlipX = (flipX != _frame.flipX);
        if (animation.curAnim != null)
        {
            return (doFlipX != animation.curAnim.flipX);
        }
        return doFlipX;
    }

@Gama11
Copy link
Member

Gama11 commented Dec 4, 2015

Yes.

@larsiusprime
Copy link
Member Author

Cool. Incoming.

@MSGhero
Copy link
Member

MSGhero commented Dec 4, 2015

Oh, right. Yeah this looks a bit nicer.

@larsiusprime
Copy link
Member Author

Is this good to go then @Gama11 and @MSGhero or does it need more changes?

@MSGhero
Copy link
Member

MSGhero commented Dec 5, 2015

Why are flipX and Y parameters added only to a couple of the flxanimcontroller functions?

@larsiusprime
Copy link
Member Author

The use case I have in mind is that you set those when you create a new animation, so I put it in the functions that create new FlxAnimations. Are there some others you think it should be added to? If so, which ones?

EDIT: Oh I see, I missed a bunch.

@MSGhero
Copy link
Member

MSGhero commented Dec 5, 2015

👍 I guess it doesn't make sense adding it to append().

@larsiusprime
Copy link
Member Author

Ready for final review @MSGhero @Gama11

@MSGhero
Copy link
Member

MSGhero commented Dec 7, 2015

I can't test it right now, but it looks fine to me.

@larsiusprime
Copy link
Member Author

Bump for final review?
@Beeblerox @gamedevsam @Gama11

Gama11 added a commit that referenced this pull request Dec 8, 2015
Add "flipX / flipY" property to animations
@Gama11 Gama11 merged commit c586ecb into HaxeFlixel:dev Dec 8, 2015
@larsiusprime larsiusprime deleted the anim_flip branch December 10, 2015 14:17
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.

3 participants