Using mirrored quads in a spritebatch?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
rougan
Citizen
Posts: 58
Joined: Wed Aug 12, 2015 10:30 am

Using mirrored quads in a spritebatch?

Post by rougan »

Hi there,
I'm looking for a way to add a combination of normal and mirrored instances of a
quad to a spritebatch. (I'm adding objects to an isometric map)

Code: Select all

Quad:flip
looked like it would've done the job if it wasn't removed :(

I appreciate you can draw mirrored quads using lg.draw() but I don't think that'd be much to use to me when drawing the whole spritebatch.

I found this old answers by bartbes, but I don't really understand how I would use viewports to acheive the mirroring.. so if anybody could provide any enlightenment that'd be great!
Thanks! :nyu:
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Using mirrored quads in a spritebatch?

Post by pgimeno »

What bartbes said means this:

Code: Select all

  local x, y, w, h = quad:getViewport()
  quad:setViewport(x, y, -w, h) -- horizontal mirror; put the sign in h for vertical mirror
What I'm not sure is whether you need to do this instead. I imagine the above is correct, but if it shows the wrong tile, try this:

Code: Select all

  local x, y, w, h = quad:getViewport()
  quad:setViewport(x+w, y, -w, h)
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Using mirrored quads in a spritebatch?

Post by slime »

You can apply the mirroring by using a negative scale parameter in SpriteBatch:add (rather than love.graphics.draw).
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Re: Using mirrored quads in a spritebatch?

Post by drunken_munki »

Both the above are correct, it works for me. I do something like this:

Code: Select all

      if object.mirror == true then
        ATLAS_SPRITEBATCH:add(object.source, object.drawx + object.w, object.drawy, object.r, -object.s, object.s)
      else
        ATLAS_SPRITEBATCH:add(object.source, object.drawx, object.drawy, object.r, object.s, object.s)
      end
The negative on the scale x will mirror, but you must add the width to offset it back into position.
User avatar
rougan
Citizen
Posts: 58
Joined: Wed Aug 12, 2015 10:30 am

Re: Using mirrored quads in a spritebatch?

Post by rougan »

Thanks so much for the replies. I managed to get it working using slime's method... I can't believe I missed that!
Post Reply

Who is online

Users browsing this forum: No registered users and 158 guests