Code: Select all
function love.load()
my=love.mouse.getY
mx=love.mouse.getX
x=0
y=0
w=0
h=0
over =false
buton_id=""
start = buton(50,50,100,100,"start")
options = buton(200,50,100,100,"options")
quit = buton(350,50,100,100,"quit")
end
function love.update(dt)
end
function love.draw()
start:draw(start.x,start.y,start.w,start.h)
quit:draw(start.x,start.y,start.w,start.h)
options:draw(start.x,start.y,start.w,start.h)
love.graphics.setColor(255,255,255)
love.graphics.print("ID of the overed button: "..tostring(buton_id),400,380)
love.graphics.print("mouse over start: "..tostring(start.overed),400,400)
love.graphics.print("mouse over quit: "..tostring(quit.overed),400,420)
love.graphics.print("mouse over optoins: "..tostring(options.overed),400,440)
end
function love.keypressed(key)
end
function love.mousepressed()
end
function buton(x,y,w,h,id,overed)
return{
x=x ,y=y ,w=w ,h=h, id=id, overed,
draw = function(self) my=love.mouse.getY() mx=love.mouse.getX()
if mx > self.x and mx < self.x+self.w and my > self.y and my < self.y+self.h then
self.overed = true
buton_id = tostring(self.id)
else
self.overed = false
buton_id = nil
end
if self.overed == true then
buton_id = tostring(self.id)
love.graphics.setColor(255,255,255)
love.graphics.print(tostring(self.id),self.x,self.y)
love.graphics.setColor(255,255,0)
love.graphics.rectangle("fill",self.x,self.y,self.w,self.h)
else
buton_id = nil
love.graphics.setColor(0,255,0)
love.graphics.print(tostring(self.id),self.x,self.y)
love.graphics.rectangle("line",self.x,self.y,self.w,self.h)
end
end
}
end
I would like to know if the code above could be a good start for a button stuff inside an app?
are there big mistake done here?
why the Id of the hovered button only return when i am on the last created button?("quit" for example)
I read this marvelous topics that helps great and got me started:viewtopic.php?f=4&t=77199&hilit=object
Kikito reply have been of great help!
I thank you for your time.
don't ask for a corrected code but want to know what i am missing.
see you