我即将完成我的游戏,但我遇到了一个错误:
attempt to compare nil with number game2.lua 444
我不知道如何解决这个问题,我已经尝试了所有的方法,但没有成功。我认为该功能scrollSpace
导致了这种情况,因为有时背景会以无法控制的速度滚动。这是我的代码:
function scrollSpace(self,event)
if self.x < -900 then
self.x = 800
else
self.x = self.x - self.speed
end
end
这控制了内容如何在屏幕上滚动。如果你们还有什么代码,请回复,我很乐意添加请求的源代码。最后一件事:有谁知道以下错误是什么意思:
attempt to compare nil with number
这是我的文件代码:
coin01 = display.newImage("coin02.png")
coin01.y = 100
coin01.x = 500
coin01.speed = math.random(2,6)
coin01.initY = mine1.y
coin01.amp = math.random(20,100)
coin01.angle = math.random(1,360)
physics.addBody(coin01, "static", {density=.1,bounce=0.1, friction=.2,radius=12})
screenGroup:insert(coin01)
end -- end of create scene
**print "passed"
function scrollSpace(self,event)
if self.x < -900 then
self.x = 800
else
self.x = self.x - self.speed
end
end**
function scene:enterScene(event)
coin01.enterFrame = coins
Runtime:addEventListener ("enterFrame",coin01)
end
function scene:exitScene(event)
***storyboard . purgeScene ("start")
story board . purgeScene ("restart")***
Runtime:removeEventListener ("enterFrame",coin01)
end
function scene:destroyScene(event)
end
scene:addEventListener("createScene",scene)
scene:addEventListener("enterScene",scene)
scene:addEventListener("exitScene",scene)
scene:addEventListener("destroyScene",scene)
return scene