love2d创建类

-- TextButton.lua
local TextButton = {
    text="",
    x=0,
    y=0,
    width=0,
    height=0
}
TextButton.__index = TextButton

function TextButton:new(text, x, y, width, height)
    local obj = {
        text = text,
        x = x,
        y = y,
        width = width,
        height = height
    }
    setmetatable(obj, self)
    return obj
end
return TextButton
-- main.lua
local TextButton = require "TextButton"

function love.load()
         local a = TextButton:new("INS", 14*2, y , 70, 27)   
end

 

posted on 2026-01-26 14:48  小沙盒工作室  阅读(2)  评论(0)    收藏  举报