Fixed buttons

This commit is contained in:
Thomas Cole 2021-02-23 17:19:00 -05:00
parent 444106377d
commit 9fa0ead644
2 changed files with 15 additions and 12 deletions

View File

@ -1,14 +1,15 @@
Button = {} Button = {}
Button.__index = Button
function Button:new(x,y,h,w,c) function Button:new(x,y,h,w,c)
o = o or {} local o = {}
setmetatable(o,self) setmetatable(o,Button)
self.__index = self o.xPos = x or 0
self.xPos = x or 0 o.yPos = y or 0
self.yPos = y or 0 o.height = h or 0
self.height = h or 0 o.width = w or 0
self.width = w or 0 o.color = c or {1,1,1}
self.color = c or {1,1,1}
return o return o
end end
@ -16,7 +17,7 @@ function Button:draw()
local r,g,b,a = love.graphics.getColor() local r,g,b,a = love.graphics.getColor()
love.graphics.setColor(self.color) love.graphics.setColor(self.color)
love.graphics.rectangle("fill", self.xPos, self.yPos, self.height, self.width) love.graphics.rectangle("fill", self.xPos, self.yPos, self.width, self.height)
love.graphics.setColor(r,g,b) love.graphics.setColor(r,g,b)
end end

View File

@ -8,11 +8,12 @@ function love.load()
love.graphics.setBackgroundColor(util.hexToLoveColor(colors.background)) love.graphics.setBackgroundColor(util.hexToLoveColor(colors.background))
width,height = love.graphics.getDimensions() width,height = love.graphics.getDimensions()
b = Button:new((width/2)-(200/2),height*.8,200,100,util.hexToLoveColor(colors.trueblue)) b = Button:new((width/2)-(200/2),height*.8,100,200,util.hexToLoveColor(colors.trueblue))
Button:new(0,height*.5,50,50,{1,0,0}) b2 = Button:new(0,height*.5,50,50,{1,0,0})
print(Button.__index)
print(b) print(b)
print(b2)
testUpgrade = Upgrade:new(1,0,1) testUpgrade = Upgrade:new(1,0,1)
@ -28,6 +29,7 @@ end
function love.draw(dt) function love.draw(dt)
b:draw() b:draw()
b2:draw()
love.graphics.printf(count, (width/2)-((width*.2)/2), height*.2, width*.2, "center") love.graphics.printf(count, (width/2)-((width*.2)/2), height*.2, width*.2, "center")