The rectangle isn't being drawn.
Posted: Fri Feb 19, 2021 8:26 pm
I am new to love2d, and this is probably a stupid question, but for some reason, my rectangle drawing function isn't working. I am trying to practice making separate files to keep the main file clean, and I am not sure if it is that the function isn't loading or that the draw function doesn't like external functions.
Code: Select all
-- main.lua
require("rectangle")
function love.load()
function rectMake()
end
end
function love.update(dt)
function rectUpdate()
end
end
function love.draw()
function drawRect()
end
end
-- rectangle.lua
function rectMake()
rect = {}
rect.x = 200
rect.y = 250
rect.wide = 100
rect.height = 100
rect.speed = 100
rect.color = {}
rect.color.red = 0
rect.color.green = 69
rect.color.blue = 255
end
function rectUpdate()
if love.keyboard.isDown("up") then
rect.y = rect.y - rect.speed * dt
end
if love.keyboard.isDown("down") then
rect.y = rect.y + rect.speed * dt
end
if love.keyboard.isDown("left") then
rect.x = rect.x - rect.speed * dt
end
if love.keyboard.isDown("right") then
rect.x = rect.x + rect.speed * dt
end
end
function drawRect()
love.graphics.setColor(rect.color.red,rect.color.green,rect.color.blue)
love.graphics.rectangle("line",rect.x,rect.y,rect.wide,rect.height)
end