Page 1 of 1

Rotate grouped images

Posted: Sun Mar 20, 2016 10:54 am
by zugende
Hi everyone,

does a function exist, which groups some images to one group so that I then can easily rotate all images together with the same origin?

At the moment I'm manipulating the offset parameter for each image.. but this is really time consuming.
Any idea how to speed up this process?

Thanks a lot! :)

Here a screenshot from a rocket (consisting of multiple images) I am trying to rotate:

Re: Rotate grouped images

Posted: Sun Mar 20, 2016 11:27 am
by Sheepolution
You can use a canvas for this

Code: Select all

function love.load()
	x = 300
	y = 100
	angle = 0
	canvas = love.graphics.newCanvas(140, 200)
end

function love.update(dt)
	if love.keyboard.isDown("up") then
		y = y - 400 * dt
	elseif love.keyboard.isDown("down") then
		y = y + 400 * dt
	end
	angle = angle + dt
end


function love.draw()
	love.graphics.setCanvas(canvas)
		love.graphics.clear()
		love.graphics.rectangle("fill", 0, 0, 20, 200)
		love.graphics.rectangle("fill", 120, 0, 20, 200)
	love.graphics.setCanvas()

	love.graphics.draw(canvas, x, y, angle, 1, 1, canvas:getWidth()/2, canvas:getHeight()/2)
end

Re: Rotate grouped images

Posted: Sun Mar 20, 2016 12:01 pm
by Ulydev
zugende wrote:same origin

Code: Select all

love.graphics.translate(origin.x, origin.y)
love.graphics.rotate(rotation)
love.graphics.translate(-origin.x, -origin.y)
drawImages()

Re: Rotate grouped images

Posted: Sun Mar 20, 2016 12:57 pm
by zugende
Ahh nice! Thank you both. Canvas is the one I was looking for.

Re: Rotate grouped images

Posted: Sun Mar 20, 2016 5:06 pm
by s-ol
zugende wrote:Ahh nice! Thank you both. Canvas is the one I was looking for.
I would still urge you to learn the transforms API, it is a very essential part of graphics programming and useful for a lot of different things.

Re: Rotate grouped images

Posted: Sun Mar 20, 2016 6:31 pm
by zugende
s-ol wrote: I would still urge you to learn the transforms API, it is a very essential part of graphics programming and useful for a lot of different things.
Lets take the attached love file as example. Eventually I want the rocket to rotate together with the "fire" - would you suggest doing this with canvas or the transform API?

Press A or D for acceleration. :)

Thanks a lot!
zugende

Re: Rotate grouped images

Posted: Sun Mar 20, 2016 10:51 pm
by s-ol
zugende wrote:
s-ol wrote: I would still urge you to learn the transforms API, it is a very essential part of graphics programming and useful for a lot of different things.
Lets take the attached love file as example. Eventually I want the rocket to rotate together with the "fire" - would you suggest doing this with canvas or the transform API?

Press A or D for acceleration. :)

Thanks a lot!
zugende
Theres no reason to use the canvas when you are going to clear and redraw it every frame (except for some very rare cases in which a Canvas has another advantage, but that won't be the case here).