Page 1 of 1

little problem with rotation

Posted: Sat Apr 29, 2017 1:14 pm
by PGUp
hi, so i made 2 rectangles, the first rectangle has rotation code, the second is just a normal rectangle, so when the first rectangle rotate, the second one will rotate too, and it isnt what i want... i tried using "for" and it didnt work and i already scrolling through forum about it, one of the post say that it need the "push" and "pop" code in it, and i didnt understand, even after reading the documentation.. help ?

Code: Select all

 
function love.load()
	stage = {}
	player = {}
	player.y = 300
	player.x = 400
	player.rotation = 45
	player.width = 50
	player.height = 50
	table.insert(stage, player)
	
	stage2 = {}
	player2 = {}
	player2.x = 100
	player2.y = 100
	player2.width = 50
	player2.height = 50
	table.insert(stage2, player2)
end

function love.update(dt)
	for i,v in pairs(stage) do
		v.rotation = v.rotation + 5 * dt
	end
end

function love.draw()
	for i,v in pairs (stage) do
	love.graphics.translate(v.x, v.y)
	love.graphics.rotate(v.rotation)
	love.graphics.setColor(255,255,255)
	love.graphics.rectangle("fill", v.width/-2, v.height/-2, v.width, v.height)
	love.graphics.push()
	love.graphics.pop()
	end
	
	for a,b in pairs (stage2) do
	love.graphics.rectangle("fill", b.x, b.y, b.width, b.height)
	end
end

Re: little problem with rotation

Posted: Sat Apr 29, 2017 1:26 pm
by pedrosgali
You need to move the push to in front of the translate.

Code: Select all

love.graphics.push()
Love.graphics.translate(x, y)
love.graphics.rotate(angle)
--draw stuff--
love.graphics.pop()
Push sets a new series of transforms on the stack, you do your transform and rotation and any scaling should yiu need to then pop discards the last changes.

Re: little problem with rotation

Posted: Sat Apr 29, 2017 1:41 pm
by PGUp
pedrosgali wrote: Sat Apr 29, 2017 1:26 pm You need to move the push to in front of the translate.

Code: Select all

love.graphics.push()
Love.graphics.translate(x, y)
love.graphics.rotate(angle)
--draw stuff--
love.graphics.pop()
Push sets a new series of transforms on the stack, you do your transform and rotation and any scaling should yiu need to then pop discards the last changes.
it works very well ! thanks alot !