Rotate images together, around the same point.

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
xtrmag
Prole
Posts: 2
Joined: Fri Feb 01, 2013 3:44 pm

Rotate images together, around the same point.

Post by xtrmag »

Hi everyone, please help me!

I want rotate images together, around the same point, here is a example code (i think it can explain more than i)
I hope i write in the right place and sorry for may bad english.

Code: Select all

local angle = 0
local image, iWidth, iHeight;
local rotate = false;

function love.load()
	image = love.graphics.newImage("/test.png");
	iWidth  = image:getWidth();
	iHeight = image:getHeight();
end

function love.draw()
	local width  = love.graphics.getWidth();
	local height = love.graphics.getHeight();
	
	love.graphics.print("Press 'q' to start or stop rotating", 10 , 10);
	
	--This is the first image
	if rotate then
		love.graphics.draw(image, (width/2), (height/2), angle);
	else
		love.graphics.draw(image, (width/2), (height/2), math.rad(0));
	end
	
	-- This is the other image with rotation. 
	-- I want to rotate (move?) this and the first image together.
	-- (Around the center of the screen, with the same distance)
	love.graphics.draw(image, (width/2), (height/2) + (iHeight), math.rad(45));

end

function love.update(dt)
    love.timer.sleep(.01)
    angle = angle + dt * math.pi/2
    angle = angle % (2*math.pi)
	
	if love.keyboard.isDown("q") then
		rotate = not rotate
	end
end
xtrmag
Prole
Posts: 2
Joined: Fri Feb 01, 2013 3:44 pm

Re: Rotate images together, around the same point.

Post by xtrmag »

After a day thinking, i decide, i will ask this, becouse i can't solve this problem by myself. and now...

Code: Select all

...
function love.draw()
	local width  = love.graphics.getWidth();
	local height = love.graphics.getHeight();
	
	love.graphics.setColorMode("combine");
	
	love.graphics.print("Press 'q' to start or stop rotating", 10 , 10);
	
	love.graphics.push()
	
	love.graphics.draw(image, (width/2), (height/2), math.rad(0));
	
	if rotate then
		love.graphics.translate(width/2, height/2)
		love.graphics.rotate(angle)
		love.graphics.translate(-width/2, -height/2)
	end
	
	--This is the first image
	love.graphics.draw(image, (width/2), (height/2), math.rad(0));

	-- This is the other image with rotation. 
	-- I want to rotate (move?) this and the first image together.
	-- (Around the center of the screen, with the same distance)
	love.graphics.draw(image, (width/2), (height/2) + (iHeight), math.rad(45));
	
	love.graphics.pop()
	
	love.graphics.push()
	
	if rotate then
		love.graphics.translate(width/2, height/2)
		love.graphics.rotate(angle*-1)
		love.graphics.translate(-width/2, -height/2)
	end
	
	love.graphics.setColor( 0, 0, 255, 255 )
	love.graphics.draw(image, (width/2), (height/2), math.rad(0));
	love.graphics.draw(image, (width/2), (height/2) + (iHeight), math.rad(45));
	love.graphics.setColor( 255, 0, 0, 255 )
	
	love.graphics.pop()

end
...
Know anyone better solution to this?
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Rotate images together, around the same point.

Post by Ref »

Could just rotate coordinates for drawing images.
(repalce rectangles with draw in demo)
Attachments
center_rotate.love
Maybe?
(745 Bytes) Downloaded 144 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests