【发布时间】:2021-03-26 17:37:11
【问题描述】:
我有一个名为“编辑”的课程
function Edit:new(x,y,w,h,text,fnt)
o = {}
setmetatable(o,EditMt)
self.__index = self
self.x = x or 0
self.y = y or 0
self.width = w or 10
self.height = h or 10
self.text = text or ""
self.active = false
self.font = fnt or font
self.yo = -(self.height - self.font:getHeight()) / 2
return o
end
并且该类有一个名为 draw(使用 Löve2d 制作)的函数
function Edit:draw( )
if self.active then
love.graphics.setColor(255,255,255,255)
love.graphics.rectangle("fill",self.x,self.y,self.width,self.height)
love.graphics.setColor(0,0,0,255)
love.graphics.printf(self.text,self.font,self.x,self.y,self.width, "center",0,1,1,0,self.yo)
else
love.graphics.setColor(255,255,255,255)
love.graphics.rectangle("line",self.x,self.y,self.width,self.height)
love.graphics.printf(self.text,self.font,self.x,self.y,self.width, "center",0,1,1,0,self.yo)
end
end
我主要创建了 2 个
edit1 = Edit:new(10,10,60,50,"1")
edit2 = Edit:new(80,10,60,50,"2")
并在回调中绘制它们
function love.draw( )
edit1:draw()
edit2:draw()
end
但它只绘制edit2?如果我在draw中切换位置,它仍然只绘制edit2,但如果我在主创建它们时切换它们的位置,它现在只绘制edit1?
【问题讨论】: