1
如何在Love2D中的子类中调用超类方法?在Love2D中超类调用超类方法
Sprite = {}
function Sprite:new(x, y, image)
local self = {}
self.x = x
self.y = y
self.image = image
function self:draw()
love.graphics.draw(self.image, self.x, self.y)
end
return self
end
ExplorerWindow = {}
function ExplorerWindow:new(x, y, image)
local self = Sprite:new(x, y, image)
function self:draw()
-- Here I want to call draw in Sprite
end
return self
end
function love.load()
explorerWindow = ExplorerWindow:new(200, 200, love.graphics.newImage("res/window.png"))
end
function love.draw()
explorerWindow:draw()
end