## Rotating in love.graphics.rectangle [SOLVED]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
test
Prole
Posts: 28
Joined: Sun Apr 14, 2019 2:36 pm

### Rotating in love.graphics.rectangle [SOLVED]

Code: Select all

for i, v in ipairs(projectiles) do love.graphics.rectangle('fill', v.x, v.y, v.w, v.h, v.angle) end
Hello. I have this code. If I use image, i can rotate it. But is there a way to do it by drawing rectangle?
Last edited by test on Tue May 07, 2019 7:33 pm, edited 1 time in total.

keharriso
Citizen
Posts: 73
Joined: Fri Nov 16, 2012 9:34 pm

### Re: Rotating in love.graphics.rectangle

Try this:

Code: Select all

for i, v in ipairs(projectiles) do
love.graphics.push()
love.graphics.translate(v.x + v.w/2, v.y + v.h/2)
love.graphics.rotate(v.angle)
love.graphics.translate(-v.w/2, -v.h/2)
love.graphics.rectangle("fill", 0, 0, v.w, v.h)
love.graphics.pop()
end

LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games

pgimeno
Party member
Posts: 1943
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

### Re: Rotating in love.graphics.rectangle

Alternatively, you can create a 1x1 image and scale it to the rectangle size.

Code: Select all

local rotation = math.rad(30)
local rect1x1 = love.graphics.newImage(love.image.newImageData(1, 1, "rgba8", "\255\255\255\255"))
function love.draw()
love.graphics.draw(rect1x1, 400, 300, rotation, 150, 100)
end


### Who is online

Users browsing this forum: Google [Bot] and 3 guests