Rotate grouped images

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
zugende
Prole
Posts: 12
Joined: Sun Feb 21, 2016 5:47 pm

Rotate grouped images

Post 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:
Attachments
rocket.png
rocket.png (4.9 KiB) Viewed 2422 times
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: Rotate grouped images

Post 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
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: Rotate grouped images

Post 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()
User avatar
zugende
Prole
Posts: 12
Joined: Sun Feb 21, 2016 5:47 pm

Re: Rotate grouped images

Post by zugende »

Ahh nice! Thank you both. Canvas is the one I was looking for.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Rotate grouped images

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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
zugende
Prole
Posts: 12
Joined: Sun Feb 21, 2016 5:47 pm

Re: Rotate grouped images

Post 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
Attachments
rocket_test.love
(8.39 KiB) Downloaded 86 times
rocket.png
rocket.png (14.48 KiB) Viewed 2344 times
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Rotate grouped images

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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest