Rotating in love.graphics.rectangle [SOLVED]

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
test
Prole
Posts: 28
Joined: Sun Apr 14, 2019 2:36 pm

Rotating in love.graphics.rectangle [SOLVED]

Post by test » Thu May 02, 2019 6:31 pm

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.

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

Re: Rotating in love.graphics.rectangle

Post by keharriso » Thu May 02, 2019 7:54 pm

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

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

Re: Rotating in love.graphics.rectangle

Post by pgimeno » Thu May 02, 2019 8:28 pm

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

Post Reply

Who is online

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