paint help

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
silverknight108
Prole
Posts: 17
Joined: Wed Oct 30, 2013 5:24 pm

paint help

Post 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
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: paint help

Post by jjmafiae »

Love isn't the best tool for creating a paint program.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: paint help

Post 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
User avatar
silverknight108
Prole
Posts: 17
Joined: Wed Oct 30, 2013 5:24 pm

Re: paint help

Post 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 :cool: :awesome:
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: paint help

Post 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.
Attachments
dragPaint.love
(397 Bytes) Downloaded 143 times
simplePaint.love
(302 Bytes) Downloaded 121 times
User avatar
silverknight108
Prole
Posts: 17
Joined: Wed Oct 30, 2013 5:24 pm

Re: paint help

Post 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
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: paint help

Post by micha »

You can change the drawing color with

Code: Select all

love.graphics.setColor(r,g,b)
Insert this into the love.keypressed-event.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest