I'm currently making a drawing program (a MS paint clone) and I can draw by clicking on the screen but that's a bit of a pain so I want to be able to draw by holding down the mouse button and drag the mouse cursor around on my screen, so here's the code:
Code: Select all
function love.load()
squares = {}
xPos = 0
yPos = 0
--Draws canvas
canvas = love.graphics.newCanvas(800, 480)
end
function love.update( dt )
local newPosition = {}
if love.mouse.isDown( "l" ) then
newPosition.x = x
newPosition.y = y
table.insert( squares, newPosition )
end
local newPosition = {}
if love.mouse.isDown("l" ) then
newPosition.x = x
newPosition.y = y
end
end
-- Draws All The Graphics --
function love.draw()
-- Prints X And Y Position On The Upper Left Screen
local x, y = love.mouse.getPosition()
love.graphics.print("X:" ..x, 10, 10)
love.graphics.print("Y:" ..y, 10, 40)
-- Set The Background To White
love.graphics.setBackgroundColor(255, 255, 255)
-- UI: Banner Grey
love.graphics.setColor(195 , 195, 195)
love.graphics.rectangle("fill", 0, 480, 800, 120)
-- Draws A 16x16 Square That Follows The Mouse
love.graphics.rectangle("line", x, y, 16, 16)
-- Draws A 16x16 Square "brush"
for key, square in ipairs( squares ) do
love.graphics.rectangle( "fill", square.x, square.y, 16, 16 )
end
end
Code: Select all
love.graphics.rectangle( "fill", square.x, square.y, 16, 16 )