bartbes wrote:
And, if you modify conf.lua it isn't in the .love, it'd be in the save folder as well.
I didn't even think about that, well I'll give it a shot later.
But for now I habe a new question to pester you with
I'm currently using button.lua from the NO demo to create buttons.
Code: Select all
-----------------------
-- NO: A game of numbers
-- Created: 23.08.08 by Michael Enger
-- Version: 0.2
-- Website: http://www.facemeandscream.com
-- Licence: ZLIB
-----------------------
-- Handles buttons and such.
-----------------------
Button = {}
Button.__index = Button
function Button.create(text,x,y)
local temp = {}
setmetatable(temp, Button)
temp.hover = false -- whether the mouse is hovering over the button
temp.click = false -- whether the mouse has been clicked on the button
temp.text = text -- the text in the button
temp.width = font["large"]:getWidth(text)
temp.height = font["large"]:getHeight()
temp.x = x - (temp.width / 2)
temp.y = y
return temp
end
function Button:draw()
love.graphics.setFont(font["large"])
if self.hover then love.graphics.setColor(unpack(color["main"]))
else love.graphics.setColor(unpack(color["text"])) end
love.graphics.print(self.text, self.x, self.y)
end
function Button:update(dt)
self.hover = false
local x = love.mouse.getX()
local y = love.mouse.getY()
if x > self.x
and x < self.x + self.width
and y > self.y - self.height
and y < self.y then
self.hover = true
end
end
function Button:mousepressed(x, y, button)
if self.hover then
if audio then
love.audio.play(sound["click"])
end
return true
end
return false
end
So I can create buttons fine with that, but I'd like to be able to create "small" buttons too, something like this:
Code: Select all
Button = {}
Button.__index = Button
function Button.create(text,x,y,font) -- example Button.create("This is a test", 100, 100, font["small"])
local temp = {}
setmetatable(temp, Button)
temp.hover = false -- whether the mouse is hovering over the button
temp.click = false -- whether the mouse has been clicked on the button
temp.text = text -- the text in the button
temp.width = font:getWidth(text)
temp.height = font:getHeight()
temp.x = x - (temp.width / 2)
temp.y = y
return temp
end
function Button:draw()
love.graphics.setFont(font["large"])
if self.hover then love.graphics.setColor(unpack(color["main"]))
else love.graphics.setColor(unpack(color["text"])) end
love.graphics.print(self.text, self.x, self.y)
end
Is a function possible like this? (I'm pretty sure what I did above doesn't work)
Also if it is, how do I hand the font to be used over to the Button:draw() function?