help needed drawing lines
Posted: Thu Jan 18, 2018 3:33 am
I'm trying to make a sort of "drawing" program that simulates the LJN video art. I've done this before in Scratch (link here: https://scratch.mit.edu/projects/198480274/), but I want to port it to Löve. I have a basic cursor working, but It to leave a line behind when pressing a key. I thought of just creating a trail of rectangles, but the tutorial I'm learning the code to place said rectangles (https://www.youtube.com/watch?v=FUiz1kL0QtI) is very outdated and doesn't work(and yes i know about the changed space key thing, the problem is with the "for _,v do". Plus I imagine that generating that many rectangles will destroy the FPS. I'm a newcomer to Löve2D and I thought this would be a simple starter game to make. For the record, I don't care about saving Images, or using the mouse, I want to strictly use arrow keys or a joystick. Please help.
oh and here is what I have so far for code, its just a cursor.
oh and here is what I have so far for code, its just a cursor.
Code: Select all
function love.load()
cursor = {}
cursor.x = 385
cursor.y = 285
cursor.pixel = {}
cursor.draw = function()
pixel = {}
pixel.x = cursor.x
pixel.y = cursor.y
table.insert(cursor.pixel, pixel)
end
end
function love.draw(dt)
love.graphics.setColor( 100, 100, 100)
love.graphics.rectangle("fill", cursor.x, cursor.y, 3, 3)
end
function love.update(dt)
--cursor movement
if love.keyboard.isDown("up") then
cursor.y = cursor.y - 20
elseif love.keyboard.isDown("down") then
cursor.y = cursor.y + 20
end
if love.keyboard.isDown("left") then
cursor.x = cursor.x - 20
elseif love.keyboard.isDown("right") then
cursor.x = cursor.x + 20
end
--thx drunken_munki for help with diagonals
--cursor bounds
if cursor.y < 0 then
cursor.y= 1
end
if cursor.y > 600 then
cursor.y= 599
end
if cursor.x < 0 then
cursor.x= 1
end
if cursor.x > 800 then
cursor.x= 799
end
--drawing control
if love.keyboard.isDown("space") then
table.insert(cursor.pixel, pixel)
end
end