I'm new to the forum, to LOVE and to Lua as well, and I'm here because I'm really excited about learning the mechanics of the language and the framework.
My use of LOVE for now is not strictly game dev, but more to create a GUI that can transform upon key presses. In particular, I'm trying to draw some black squares in a row when clicking "c" on the keyboard and to remove them when clicking "delete", much like typing a text.
For now I'm trying to not go for OOP, as my understanding of it is still pretty low.
I've created a code that I hope you can forgive me for, which looks like this:
Code: Select all
_G.love = require("love")
Keyboard = love.keyboard
love.graphics.setBackgroundColor(1, 1, 1)
_G.mainCanvas = love.graphics.newCanvas()
_G.mainCanvasScroll = {}
_G.mainCanvasScroll.h = 0 -- horizontal scroll
_G.mainCanvasScroll.v = 0 -- vertical scroll
_G.love.graphics.setCanvas(mainCanvas)
love.graphics.setColor(0,0,0)
local square = {
canvas=love.graphics.newCanvas(100, 100),
placementX = 0,
placementY = 100
}
_G.love.graphics.setCanvas(square)
_G.rectangle = love.graphics.rectangle("fill", 0, 0, 100, 100)
_G.squareSet = {}
function love.update(dt)
--scroll
if Keyboard.isDown("left") and (Keyboard.isDown("lctrl") or Keyboard.isDown("rctrl")) then
mainCanvasScroll.h = mainCanvasScroll.h + 10
--print(mainCanvasScroll.h)
end
if Keyboard.isDown("right") and (Keyboard.isDown("lctrl") or Keyboard.isDown("rctrl")) then
mainCanvasScroll.h = mainCanvasScroll.h - 10
--print(mainCanvasScroll.h)
end
if Keyboard.isDown("c") then
square.placementX = square.placementX + 100
love.timer.sleep(0.09)
table.insert(squareSet, square)
print(square.placementX)
end
if Keyboard.isDown("backspace") then
if square.placementX > 0 then
square.placementX = square.placementX - 100
love.timer.sleep(0.09)
else end
table.remove(squareSet, #squareSet)
print(square.placementX)
end
end
function love.draw()
love.graphics.setCanvas(mainCanvas)
for i = 1, #squareSet do
love.graphics.draw(
squareSet[i].canvas,
square.placementX,
square.placementYent)
--print(squareSet[#squareSet])
love.graphics.setCanvas()
end
love.graphics.setCanvas(mainCanvas)
love.graphics.setCanvas()
love.graphics.draw(mainCanvas, mainCanvasScroll.h, mainCanvasScroll.v)
end
Code: Select all
mainCanvas
Code: Select all
square.canvas
Code: Select all
rectangle("fill", 0, 0, 100, 100)
The problem is: the squares are not appearing on the screen.
I've tried to make sure that the order of the different
Code: Select all
setCanvas
Code: Select all
love.draw()
Do you have any suggestions about this issue?
Thank you in advance.
Giuliano