Hi again!
So I got the idea of trying to create a very simple drawing program where you can left click anywhere on the love window and draw a point there.
So I'm using the love.mousepressed and love.mousereleased functions to get the mouse position and draw a point there, but the point doesn't stay. As
soon as the mouse button is released the point disappears. I'm not sure what to do to make the point stay. Here is what I have:
function love.load()
love.graphics.setColor(255,255,255)
love.graphics.setPointSize(10)
end
function love.update(dt)
end
function love.draw()
end
function love.mousepressed()
mouseX=love.mouse.getX()
mouseY=love.mouse.getY()
end
function love.mousereleased()
love.graphics.point(mouseX,mouseY)
end
problems with making very simple drawing love app
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: problems with making very simple drawing love app
you aren't saving the points anywhere. at absolute least you'd want to have it so on mousereleased you do a table.insert(sometable, {MouseX, MouseY}), and then draw with a for loop.
so :you could have a timer function to remove points over time, or fade their transparency or something, but that's for you to implement. you shouldn't be using drawing functions (love.graphics) anywhere but in love.draw really..
so :
Code: Select all
function love.load()
love.graphics.setColor(255,255,255)
love.graphics.setPointSize(10)
points = {}
end
function love.update(dt)
--nothing
end
function love.draw()
for k,v in ipairs(points) do
love.graphics.point(v[1],v[2])
end
end
function love.mousepressed()
mouseX=love.mouse.getX()
mouseY=love.mouse.getY()
end
function love.mousereleased()
table.insert(points, {mouseX,mouseY})
end
Re: problems with making very simple drawing love app
Thanks for your post.
Because of it, I read a short tutorial on lua tables to try and understand your solution to my problem, and I figured out how to create a simple undo function for my drawing app by using table.remove()
I also changed the program to draw 1 by 1 pixel sized rectangles, so that the program would be more like an actual pixel art drawing app. (as opposed to using the point function which draws circular points)
Again, thanks for the help!
Because of it, I read a short tutorial on lua tables to try and understand your solution to my problem, and I figured out how to create a simple undo function for my drawing app by using table.remove()
I also changed the program to draw 1 by 1 pixel sized rectangles, so that the program would be more like an actual pixel art drawing app. (as opposed to using the point function which draws circular points)
Again, thanks for the help!
Re: problems with making very simple drawing love app
no worries, pleased to help.
Re: problems with making very simple drawing love app
Well, if you could help with one other thing...
How could I make the program so that it would let the user draw freely instead of pixel by pixel? I thought of having a loop going in the love.mousepressed function but I'm not exactly sure how to implement it, or if that's even the way to do it.
How could I make the program so that it would let the user draw freely instead of pixel by pixel? I thought of having a loop going in the love.mousepressed function but I'm not exactly sure how to implement it, or if that's even the way to do it.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: problems with making very simple drawing love app
try using something like
in your love.update(dt) callback.
Code: Select all
if love.mouse.isDown("lb") then
//draw pixel at x,y
end
Re: problems with making very simple drawing love app
1st edit: on second thought, maybe I should just try it out!
2nd edit: btw I did it, was actually quite easy!
2nd edit: btw I did it, was actually quite easy!
Who is online
Users browsing this forum: No registered users and 3 guests