Reverse / mirror AnimatedSprite

I'm sure there is a very simple solution but how do I mirror an AnimatedSprite pulled in from SpriteLoq? I have animation for walking right inside the sprite sheet and obviously don't want to have to include walk left animating since it's the same, ju…

Viewing 1 to 10 (10 Total)
Reverse / mirror AnimatedSprite

mourlamstudios

mourlamstudios
Total Posts: 152
Joined: February 12, 2012

I'm sure there is a very simple solution but how do I mirror an AnimatedSprite pulled in from SpriteLoq?

I have animation for walking right inside the sprite sheet and obviously don't want to have to include walk left animating since it's the same, just mirrored on y-axis. scaleX = -1 repositions the sprite. Any way other than this? thanks in advance!

Tags:
Posted on June 28, 2012 at 10:21 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: Reverse / mirror AnimatedSprite

It might be possible to do this in the parsing stage, by creating a new animation with reversed coordinates, or perhaps we should add some kind of a reversed feature to the spritesheet library?

Posted on June 29, 2012 at 2:32 AM

mourlamstudios

mourlamstudios
Total Posts: 152
Joined: February 12, 2012

Re: Reverse / mirror AnimatedSprite

I see SpriteLoq has Reverse Animation checkbox for each behavior. Can we use this feature in Animated Sprite?

It would be amazing if we had an extra parameter to mirror animations on specified axis. This is something that should be very common with plat former games right?

Posted on June 29, 2012 at 9:49 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: Reverse / mirror AnimatedSprite

Give the option a try in SpriteLoq and let me know how it goes/what it does smiling

Posted on June 30, 2012 at 12:54 PM

mourlamstudios

mourlamstudios
Total Posts: 152
Joined: February 12, 2012

Re: Reverse / mirror AnimatedSprite

Reverse Animation plays the animation backwards. It doesn't mirror the sprite

Posted on June 30, 2012 at 1:02 PM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: Reverse / mirror AnimatedSprite

Ah, makes sense.

This should probably be a feature of the spritesheet library, perhaps when you play a behavior, or perhaps there should be a way to create a duplicate behavior, using a transform from an existing behavior. That's a feature I had in my old spritesheet library. You could create a "duplicate behavior" which was identical to another, but with adjustments, which I used for flipping.

If you want to take a crack at improving this, that would be great, or I can take a look when I am able

Posted on June 30, 2012 at 1:13 PM

KidVeno

KidVeno
Total Posts: 5
Joined: March 12, 2012

Re: Reverse / mirror AnimatedSprite

Are transformations of the animated sprites bitmap.bitmapdata using a matrix an option

var matrix = new matrix(-1,0,0,1,width_of_animationFrame,0)


Then call draw

Somebitmapdata.draw(Currentframe_bitmapdata,matrix,null,null,null, true)

I don't use the spritesheet classes so I'm not sure this is acceptable. I use my own sprite lib(not really a library more like 3 classes, more so a book or pamphlet lol) but I can send you them, or modifying the spritesheet package

Posted on July 01, 2012 at 11:30 PM

Huge

Huge
Total Posts: 546
Joined: October 07, 2011

Re: Reverse / mirror AnimatedSprite

Hi,
If you are using drawTiles, you can use the 2x2 transform to flip the x with [ -1, 0 0, 1].
Or y: [ 1 0 0 -1 ]

Hugh

Posted on July 02, 2012 at 1:21 AM

mourlamstudios

mourlamstudios
Total Posts: 152
Joined: February 12, 2012

Re: Reverse / mirror AnimatedSprite

Thank you for the advice. I'm pretty sure i remember a post by josh saying he uses a sequence of BitmapData objects b/c it was faster than drawTiles for AnimatedSprite so maybe the matrix option will work. Thanks again.

Posted on July 02, 2012 at 7:30 AM

Huge

Huge
Total Posts: 546
Joined: October 07, 2011

Re: Reverse / mirror AnimatedSprite

Hi,
I think the performance difference will be minimal, since they are doing almost the same thing, so it becomes a question of convenience.

I think you can do it like this.

shape = new Shape();
shape.graphics.beginBitmapFill( bmp, matrix);
shape.graphics.drawRect(...)

shape.x = 10;
shape.y = 10;

So bmp will be constant (your sprite sheet) the drawRect will be a constant rect depending on the size of you "sprite", say -10,-10, 20, 20
and "matrix" will depend on your sub-rect and whether you want the graphics flipped.

So, your "animation" class might look like this:

class Animation
{
var bitmap:BitmapData;
var sizeX:Float;
var sizeX:Float;
var frame:Array<Matrix>;
}


You can calculate the matrix by first using Matrix.createGradientBox, and then negating with the "a" or "d" terms and translating the "tx" and "ty" terms.
This can mess with your head a bit, but trial and error should get you there.

Alternatively, you could use the "drawTriangles" method, and your frames would be sets of UV coordinates.

Hugh

Posted on July 03, 2012 at 12:01 AM