problems with making very simple drawing love app

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
alex_
Prole
Posts: 19
Joined: Sat Jan 16, 2010 11:39 pm

problems with making very simple drawing love app

Post by alex_ »

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
Geti
Party member
Posts: 112
Joined: Tue Oct 20, 2009 6:38 am

Re: problems with making very simple drawing love app

Post by Geti »

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 :

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
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..
alex_
Prole
Posts: 19
Joined: Sat Jan 16, 2010 11:39 pm

Re: problems with making very simple drawing love app

Post by alex_ »

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!
Geti
Party member
Posts: 112
Joined: Tue Oct 20, 2009 6:38 am

Re: problems with making very simple drawing love app

Post by Geti »

no worries, pleased to help.
alex_
Prole
Posts: 19
Joined: Sat Jan 16, 2010 11:39 pm

Re: problems with making very simple drawing love app

Post by alex_ »

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.
User avatar
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

Post by TechnoCat »

try using something like

Code: Select all

if love.mouse.isDown("lb") then
//draw pixel at x,y
end
in your love.update(dt) callback.
alex_
Prole
Posts: 19
Joined: Sat Jan 16, 2010 11:39 pm

Re: problems with making very simple drawing love app

Post by alex_ »

1st edit: on second thought, maybe I should just try it out!

2nd edit: btw I did it, was actually quite easy!
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests