Page 1 of 1
paint help
Posted: Tue Mar 18, 2014 4:05 pm
by silverknight108
hello i am trying to make a paint program i works very simple but when i click a second time it doesn't make a new pixel it moves the origanil pixel. Im hoping you could check out my code and see what is wrong.
Code: Select all
function love.load()
mousex = 0
mousey = 0
clicked = false
cursor = love.mouse.newCursor("images/brush.png", 1, 1 )
love.mouse.setCursor(cursor)
end
function love.update(dt)
end
function love.draw()
if clicked == true then
love.graphics.circle("fill",mousex,mousey,5,100)
end
end
function love.mousepressed(x,y,button)
if button == "l" then
clicked = true
mousex = x
mousey = y
end
end
function love.mousereleased(x, y, button)
clicked = false
end
Re: paint help
Posted: Tue Mar 18, 2014 4:49 pm
by jjmafiae
Love isn't the best tool for creating a paint program.
Re: paint help
Posted: Tue Mar 18, 2014 5:32 pm
by micha
What you program does, is saving the coordinates of the last clicked position and draws a circle at that place. I'd call that a vector graphics approach. What you probably want is a pixel graphics approach. That means that you would not store the positions of individual objects, but instead store the color of each pixel on screen. That can be done using a
Canvas. (warning: Canvases are not supported by all graphics cards. So your game might not run on every computer).
The code would look like this:
Code: Select all
love.load()
-- create canvas
end
love.draw()
-- draw canvas to screen
end
love.mousepressed(x,y,button)
-- draw stuff to canvas
end
Re: paint help
Posted: Tue Mar 18, 2014 6:33 pm
by silverknight108
thanks sort of I don't really get how to make that as i never used canvases beforeif you could provide a tutorial for canvases that could be great also just saying the code on how to do it would be fine
look at my horse my horse is amazing taste my horese he taste like a raisin
Re: paint help
Posted: Tue Mar 18, 2014 8:04 pm
by micha
Sure, here is an example of using a canvas. Start the game and click anywhere to place circles.
Edit: I also added a .love example for drawing lines by holding down the mouse button.
Re: paint help
Posted: Wed Mar 19, 2014 7:53 pm
by silverknight108
thanks a lot i will stare at it for a long time till i get it on friday this week meanwhile how do you make changing color using the number keys
Re: paint help
Posted: Wed Mar 19, 2014 8:56 pm
by micha
You can change the drawing color with
Insert this into the love.keypressed-event.