Page 1 of 1

Mirroring Sprites (Using Quads)

Posted: Sat Feb 23, 2013 8:57 pm
by CagedWalrus
Hello,

I have a really quick question in regards to Quads. Is it possible to mirror an image, that the quad is referencing (a sprite sheet, for instance), on the fly?
Say, for instance, when you are pressing "right" it uses the reference image, but when you press "left" it mirrors the reference image.

I've looked around on the boards, but didn't come across anything that seemed 100% appropriate. I apologize in advance if this is a common topic, but it didn't appear to be mentioned.

I suspect that when drawing the image you can use the additional variables(rotation, scale, etc) to alter the orientation, but I'm not at a computer that I can test this on and it's been killing me to try and figure out.

Thanks!

Re: Mirroring Sprites (Using Quads)

Posted: Sat Feb 23, 2013 8:59 pm
by pakoskyfrog
http://www.love2d.org/wiki/love.graphics.drawq

If you look at this, you can see there are the scales factors, and if you put -1 in one of them, you get a flip !

Re: Mirroring Sprites (Using Quads)

Posted: Sat Feb 23, 2013 9:36 pm
by CagedWalrus
Great, thank you for a quick response!

If I'm mirroring the original image, does this require me to also put in a number for the offset? I'm trying to think about how this would look inside the draw function.

I suppose it could look something like this:

Code: Select all

function love.draw()

love.graphics.drawq(img, quad[direction][iterator], char.x, char.y, 0, char.scale, 1, char.width)

end
Then based on the direction, I could change the variable accordingly? I'm somewhat new to this, so you have my apologies it this is a very novice question.

Thank you!

Re: Mirroring Sprites (Using Quads)

Posted: Sat Feb 23, 2013 10:54 pm
by spectralcanine
You need an offset, but I think it's easier to offset the image so that its center is on the origin, like so:

Code: Select all

dir = 1 -- to mirror set to -1
img = ...
origin = {x = img:getWidth() * 0.5, y = img:getHeight() * 0.5}

love.graphics.draw(img, x, y, r, dir, 1, origin.x, origin.y)

Re: Mirroring Sprites (Using Quads)

Posted: Sat Feb 23, 2013 11:11 pm
by CagedWalrus
Awesome, thank you for the reply. I have it working properly at the moment, but now I'm having a strange issue with animation smoothness.