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 .
rougan
Citizen
Posts: 58 Joined: Wed Aug 12, 2015 10:30 am
Post
by rougan » Sun Jan 28, 2018 11:59 pm
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)
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!
pgimeno
Party member
Posts: 3548 Joined: Sun Oct 18, 2015 2:58 pm
Post
by pgimeno » Mon Jan 29, 2018 3:22 am
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)
slime
Solid Snayke
Posts: 3132 Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:
Post
by slime » Mon Jan 29, 2018 12:08 pm
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
Post
by drunken_munki » Mon Jan 29, 2018 1:27 pm
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.
rougan
Citizen
Posts: 58 Joined: Wed Aug 12, 2015 10:30 am
Post
by rougan » Tue Jan 30, 2018 9:15 pm
Thanks so much for the replies. I managed to get it working using slime's method... I can't believe I missed that!
Users browsing this forum: No registered users and 158 guests