little problem with rotation

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

little problem with rotation

Post 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
-
pedrosgali
Party member
Posts: 107
Joined: Wed Oct 15, 2014 5:00 pm
Location: Yorkshire, England

Re: little problem with rotation

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

Code: Select all

if not wearTheseGlasses() then
  chewing_on_trashcan = true
end
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

Re: little problem with rotation

Post 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 !
-
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 83 guests