quad resize

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
Divinity
Prole
Posts: 7
Joined: Thu Nov 21, 2024 2:23 pm
Location: Portugal

quad resize

Post by Divinity »

im creating an animation by caching quads from a tileset of 256*256
this means it's 16 frames of 64*64 images

question is, im not sure im understanding how quads work. if i create this animation (eg.: on my cursor's position), will the animation be made of 64*64 images because each quad is that size? i wanted it custom size
poof()
User avatar
marclurr
Party member
Posts: 158
Joined: Fri Apr 22, 2022 9:25 am

Re: quad resize

Post by marclurr »

You can create the quads with whatever dimensions you want but they can't be resized after creation. https://love2d.org/wiki/love.graphics.newQuad
User avatar
Divinity
Prole
Posts: 7
Joined: Thu Nov 21, 2024 2:23 pm
Location: Portugal

Re: quad resize

Post by Divinity »

Image
(image not showing? https://imgur.com/43sPEUx)

in my example, i made a quad on my cursor (position 64, 128), which is the tileset's 10th sprite
but how to set a custom size? let's say i want that same one, but sized 50x50


Code: Select all

	local parent_effect = GRAPHICS.newImage("sprites/effects/explosion1.png")
	local quad = GRAPHICS.newQuad(64, 128, 64, 64, parent_effect:getDimensions())
	GRAPHICS.draw(parent_effect, quad, mouseX, mouseY)
poof()
User avatar
marclurr
Party member
Posts: 158
Joined: Fri Apr 22, 2022 9:25 am

Re: quad resize

Post by marclurr »

You mean you want to draw it at a custom size? Use the sx and sy parameters of the draw function. You'd need to work out the correct fraction of the true size to make it 50x50px (in this case 50 divided by 64, or 0.78125).

You should really get comfortable reading the documentation, finding this kind of thing out will be much quicker for you than waiting for a response on here.
https://love2d.org/wiki/love.graphics.draw
User avatar
Divinity
Prole
Posts: 7
Joined: Thu Nov 21, 2024 2:23 pm
Location: Portugal

Re: quad resize

Post by Divinity »

i read, problem is it doesnt always explain what each thing mean/does, and examples dont always use all things (obviously)
trying to find examples with quad's SX SY OX OY KX KY whatever they mean lol

my resized quad is being drawn on another position, not being drawn at cursor coordinates :(
poof()
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: quad resize

Post by RNavega »

Hi, some comments:
1) To not use any calls to the asset loading functions (like .newImage()) inside a high-frequency function, or you're gonna wear out your disk. The love.draw() function is always called at least 30 times per second (usually 60 or more), and each time it's called, you're loading that image from disk. Better to cache the image once during startup into some outer scope variable, then use that variable later as explained by pgimeno in here: viewtopic.php?p=261188#p261188

2) You need to do some math on the X, Y coordinates that you're sending to the draw() call so that the quad is positioned how you want to. The quad begins being drawn by its top-left corner, so if you want to draw it centered at the mouse cursor, you should subtract half the quad width from its desired x position, and half the quad height from its desired y position. Use the quad width and height in pixels, and already scaled by the same SX and SY scaling factors that you'll send to draw().

3) The optional OX,OY parameters control the origin offset of the scale and rotate and shearing transformations done by the optional R and SX,SY and KX,KY parameters.
The default origin is the top-left corner of the sprite, so the sprite gets scaled by that corner for example, but by using the origin offset you can scale it from its center or some other position.
This is written in the introduction to that love.graphics.draw() docs page that marclurr pointed to (it does help to have some previous experience with using sprites and 2D affine transformations, but it's too much stuff to explain in forum posts)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 12 guests