在LOVE中创建游标

我是一个新手程序员,最近开始了解将代码放在main.lua之外,因此我想为自定义游标做到这一点。最初的代码正确地显示了“cursor.png”,但修改后的版本只显示了标准游标。请问我缺失或者做错了什么?

原始代码:

love.load = function()
  cursor = love.graphics.newImage("assets/sprites/cursor.png")
  love.mouse.setVisible(false)
end

love.draw = function()
  love.graphics.setColor(1, 1, 1, 1)
  love.graphics.draw(cursor, love.mouse.getX(), love.mouse.getY())
end

修改后的代码:

local load = function(cursor)
  love.mouse.setVisible(false)
  local inst = {}
    inst.cursor = love.graphics.newImage("assets/sprites/cursor.png")
  return inst
end

local draw = function(color, image)
  local inst = {}
  inst.color = love.graphics.setColor(1, 1, 1, 1)
  inst.image = love.graphics.draw(cursor, love.mouse.getX(), love.mouse.getY())
  return inst
end
点赞
用户13732057
用户13732057

将下面翻译成中文并且保留原本的 markdown 格式

在几个小时后(发帖几分钟后),我找到了一个可行的解决方案。请注意,这是在“工作文件”中编码的,而不是在我的实际光标文件中,因此名称不同。

local working_file = {}

local cusorSprite

working_file.load = function(self)
  cursorSprite = love.graphics.newImage("assets/sprites/cursor.png")
  love.mouse.setVisible(false)
end

working_file.update = function(self)
end

working_file.draw = function(self)
  love.graphics.draw(cursorSprite, love.mouse.getX(), love.mouse.getY())
end

return working_file
2020-06-14 05:49:32