Page 1 of 1
How do I target the newQuad() function?
Posted: Wed Aug 24, 2022 7:27 am
by DGM
Hi,
I'm trying to load a large .png image and draw only part of it to a canvas. My understanding is that I should use a quad to lift part of the image and then draw that, but I'm not seeing how to aim the newQuad() function. It's arguments don't include an image/texture/whatever argument and I don't see an equivalent of newCanvas() for these object types. How do I target the correct source when making a quad?
I'm using v11.4, in case it matters. Help is appreciated.
EDIT: Sorry, I meant "an equivalent of setCanvas()", not newCanvas().
Re: How do I target the newQuad() function?
Posted: Wed Aug 24, 2022 7:52 am
by darkfrei
So you want to use the
https://love2d.org/wiki/love.graphics.draw
Code: Select all
love.graphics.draw ( texture, quad, x, y )
and you want to create it as
https://love2d.org/wiki/love.graphics.newQuad
Code: Select all
quad = love.graphics.newQuad ( x, y, width, height, texture )
It works as:
Code: Select all
local x, y, w, h = 10, 10, 32, 16 -- quad position and quad size
local image = love.graphics.newImage ("spritesheet.png")
local quad = love.graphics.newQuad ( x, y, w, h, image )
object = {
x = 20, y=30, -- position of object
quad = quad,
image = image,
}
-- draw:
love.graphics.draw ( object.image, object.quad, object.x, object.y)
For my opinion, the quad must have the reference to the image that it uses for using as
love.graphics.drawQuad(quad,x,y), all needed references must be inside the quad, but it doesn't work (now).
Re: How do I target the newQuad() function?
Posted: Wed Aug 24, 2022 11:06 am
by BrotSagtMist
a quad contains cut and scale information.
Binding that to a picture would be contraproductive since using a quad on different pictures is a thing.
Re: How do I target the newQuad() function?
Posted: Wed Aug 24, 2022 11:24 am
by darkfrei
BrotSagtMist wrote: ↑Wed Aug 24, 2022 11:06 am
a quad contains cut and scale information.
Binding that to a picture would be contraproductive since using a quad on different pictures is a thing.
You are right, but the
other picture can be optional, if you had just one picture then you could not provide any other information, just render quad in the given position with default picture, that was based on.
Re: How do I target the newQuad() function?
Posted: Sat Aug 27, 2022 2:09 pm
by DGM
darkfrei wrote: ↑Wed Aug 24, 2022 7:52 am
local quad = love.graphics.newQuad ( x, y, w, h, image )
That's what I was missing. For some reason I was assuming that only the version of a function at the top of the page was legit and the lower ones were obsolete. Not sure why. But it caused me to miss that.
Thanks.