问题描述
所以我有这个 Util.lua 文件,我正在其中制作将在我的游戏的所有状态中使用的所有功能。
这就是我的 Util 文件的样子
function GenerateQuads(atlas,tilewidth,tileheight)
local sheetWidth = atlas:getWidth() / tilewidth
local sheetHeight = atlas:getHeight() / tileheight
local sheetCounter = 1
local spritesheet = {}
for y = 0,sheetHeight - 1 do
for x = 0,sheetWidth - 1 do
spritesheet[sheetCounter] =
love.graphics.newQuad(x * tilewidth,y * tileheight,tileheight,atlas:getDimensions())
sheetCounter = sheetCounter + 1
end
end
return spritesheet
end
function table.slice(tbl,first,last,step)
local sliced = {}
for i = first or 1,last or #tbl,step or 1 do
sliced[#sliced+1] = tbl[i]
end
return sliced
end
funtion GenerateQuadsPowerups()
local counter = 1
local quads = {}
return counter
end
请注意,最后一个函数根本不起作用,所以我只是返回计数器进行测试,给出的错误消息是:
'=' 预计在 'GenerateQuadsPowerups' 附近
“Powerup”是我使用库 class.lua 声明的类。当我从 Util.lua 中删除有问题的函数时,我在 Powerup.lua 文件中创建的第一个函数出现了同样的错误。
这里是类,以防需要参考
Powerup = Class{}
funtion Powerup:init()
self.x = VIRTUAL_WIDTH
self.y = VIRTUAL_HEIGHT
self.dx = 0
self.dy = -10
end
-- we only need to check collision with the paddle as only that collisionis relevant to this class
function Powerup:collides()
if self.x > paddle.x or paddle.x > self.x then
return false
end
if self.y > paddle.y or self.y > paddle.y then
return false
end
return true
end
funtion Powerup:update(dt)
self.y = self.y + self.dy * dt
if self.y <= 0 then
gSounds['wall-hit']:play()
self = nil
end
end
我不明白这里发生了什么
解决方法
错别字 1
功能 GenerateQuadsPowerups()
错别字 2
功能 Powerup:init()
错别字 3
功能 Powerup:update(dt)
CREATE DATABASE 'biostar';
grant all privileges on *.* to 'root'@'172.18.0.3' identified by 'biostar';
grant all privileges on *.* to 'biostar'@'172.18.0.3' identified by 'biostar';
顺便说一句。我猜你认为你可以以某种方式破坏你的 PowerUp,但它只会将 nil 分配给 self = nil
,它只是 self
的局部变量。无论如何它都会超出范围。