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.__index = Button
function Button:new(x,y,h,w,c)
o = o or {}
setmetatable(o,self)
self.__index = self
self.xPos = x or 0
self.yPos = y or 0
self.height = h or 0
self.width = w or 0
self.color = c or {1,1,1}
local o = {}
setmetatable(o,Button)
o.xPos = x or 0
o.yPos = y or 0
o.height = h or 0
o.width = w or 0
o.color = c or {1,1,1}
return o
end
@ -16,7 +17,7 @@ function Button:draw()
local r,g,b,a = love.graphics.getColor()
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)
end

View File

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