How do I target the newQuad() function?

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
DGM
Prole
Posts: 16
Joined: Tue Mar 20, 2018 6:42 am

How do I target the newQuad() function?

Post 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().
User avatar
darkfrei
Party member
Posts: 1181
Joined: Sat Feb 08, 2020 11:09 pm

Re: How do I target the newQuad() function?

Post 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)


:x 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).
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
BrotSagtMist
Party member
Posts: 614
Joined: Fri Aug 06, 2021 10:30 pm

Re: How do I target the newQuad() function?

Post 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.
obey
User avatar
darkfrei
Party member
Posts: 1181
Joined: Sat Feb 08, 2020 11:09 pm

Re: How do I target the newQuad() function?

Post 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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
DGM
Prole
Posts: 16
Joined: Tue Mar 20, 2018 6:42 am

Re: How do I target the newQuad() function?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests