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 »

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
Party member
Posts: 109
Joined: Fri Nov 16, 2012 9:34 pm

Re: Rotating in love.graphics.rectangle

Post by keharriso »

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: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Rotating in love.graphics.rectangle

Post by pgimeno »

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 1 guest