我有一个包含这组值和函数的类:
require("class")
entity = class:new()
function entity:new()
self.x = 100
self.y = 100
self.width = 32
self.height = 32
self.info = "entity"
self.alive = true
self.color = {r = 255, g = 0, b = 0}
return self
end
function entity:load()
end
function entity:update()
if self.alive then
end
end
function entity:draw()
if self.alive then
love.graphics.setColor(self.color.r, self.color.g, self.color.b)
end
end
function entity:destroy()
self.alive = false
end
我希望能够将这些相同的函数和值简单地用于其他类,如下所示:
require("entity")
local player = entity:new()
function player:load()
self.color.r = 100
end
function player:update()
end
--etc etc
我有 Flash 和 As3 背景,如果你们知道的话,您可能或多或少地理解我正在尝试做的事情。
那么有人可以帮我解决这个问题吗?感谢所有帮助。
你可以用这个类系统 https://love2d.org/wiki/Simple_Educative_Class_System获得您想要的体验。 (请务必复制完整版本的代码)。
你的代码看起来像这样:
require("class")
entity = class()
entity.x = 100
entity.y = 100
entity.width = 32
entity.height = 32
entity.info = "entity"
entity.alive = true
entity.color = {r = 255, g = 0, b = 0}
function entity:load()
end
function entity:update()
if self.alive then
end
end
function entity:draw()
if self.alive then
love.graphics.setColor(self.color.r, self.color.g, self.color.b)
end
end
function entity:destroy()
self.alive = false
end
第二个文件:
require("entity")
local player = class()
player:addparent(entity)
function player:load()
self.color.r = 100
end
function player:update()
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)