little problem with rotation
Posted: Sat Apr 29, 2017 1:14 pm
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