我试图在我的曲棍球应用中给用户一个重置按钮,但我一直收到此错误,我不知道还有什么可以尝试修复它attempt to call method 'removeSelf' (a nil value)
。我试着搬东西,但这也没有帮助。我该如何解决这个错误?请帮帮我。
我的代码:
function startGame(event)
titleScreenGroup:removeSelf()
resetScore() -- in the case that this is a rematch
placePlayerOnePaddle()
placePlayerTwoPaddle()
placePuck(puckAvalLocation.center)
Runtime:addEventListener( "postCollision", onPostCollision )
Runtime:addEventListener( "collision", onCollision )
appodeal.show("interstitial") --<-------- move this to scene:show()'s "did" phase
end
local function gameRestart(event)
if ("ended" == event.phase) then
--code here when touch begin
startGame()
end
end
function setUpGroundGraphics()
local graphic = display.newImageRect( "bg.png", 768, 1024 )
graphic.x = display.contentWidth / 2
graphic.y = display.contentHeight / 2
local graphic = display.newImageRect( "score.png", 122, 144 )
graphic.x = topLeft.x + 90
graphic.y = display.contentHeight / 2
graphic = display.newImageRect( "centerLine.png", 768, 9 )
graphic.x = display.contentWidth / 2
graphic.y = display.contentHeight / 2
graphic = display.newImageRect( "centerCircle.png", 198, 198 )
graphic.x = display.contentWidth / 2
graphic.y = display.contentHeight / 2
-- top goal line
graphic = display.newImageRect( "goalLine.png", 497, 203 )
graphic.x = display.contentWidth / 2
graphic.y = topLeft.y + wallThickness * 2 + 70
-- bottom goal line
graphic = display.newImageRect( "goalLine.png", 497, 203 )
graphic.x = display.contentWidth / 5
graphic.y = bottomRight.y - wallThickness * 2 -70
graphic.rotation = 180
resetButton = display.newImageRect( "reset.png", 508, 224 )
resetButton.x = display.contentWidth / 4.1
resetButton.y = display.contentHeight - display.contentHeight / 2.5
resetButton:scale( 0.4, 0.4 )
resetButton:addEventListener("touch", gameRestart)
end
EDIT !!这是我定义titlescreengroup
的地方local lastForce -- Used to calculate the volume of a the collision sound effects
local titleScreenGroup
function main()
display.setStatusBar( display.HiddenStatusBar )
setUpTable()
setUpTitleScreen()
end
function setUpTable()
setUpGroundGraphics()
setUpPaddleWalls()
setUpPuckWalls()
setUpScoreText();
end
function setUpTitleScreen()
titleScreenGroup = display.newGroup()
local background =
display.newImageRect("rink.jpg",display.contentWidth,display.contentHeight)
background.x = display.contentCenterX
background.y = display.contentCenterY
titleScreenGroup:insert(background)
title = display.newImageRect( "title.png", 530, 196 )
title.x = display.contentWidth / 2
title.y = display.contentHeight / 4
titleScreenGroup:insert(title)
playButton = display.newImageRect( "play.png", 508, 224 )
playButton.x = display.contentWidth / 2
playButton.y = display.contentHeight - display.contentHeight / 4
titleScreenGroup:insert(playButton)
display.getCurrentStage():insert(titleScreenGroup)
playButton:addEventListener("touch", startGame)
end
答案 0 :(得分:0)
我认为您尝试多次删除titleScreenGroup
群组。这应该有所帮助:
function startGame(event)
if titleScreenGroup then
titleScreenGroup:removeSelf()
titleScreenGroup = nil
end
resetScore() -- in the case that this is a rematch
placePlayerOnePaddle()
placePlayerTwoPaddle()
placePuck(puckAvalLocation.center)
Runtime:addEventListener( "postCollision", onPostCollision )
Runtime:addEventListener( "collision", onCollision )
appodeal.show("interstitial") --<-------- move this to scene:show()'s "did" phase
end
我还注意到,当用户触摸播放按钮时,startGame
函数被调用两次。快速修复:
function setUpTitleScreen()
...
playButton:addEventListener("touch", gameRestart)
end
答案 1 :(得分:0)
更好地使用 display.remove(object)然后 titleScreenGroup = nil https://docs.coronalabs.com/api/library/display/remove.html
2018-03-12 15:43:42,330 INFO o.a.j.t.JMeterThread: Stopping Thread: org.apache.jorphan.util.JMeterStopThreadException: The thread is scheduled to stop in -99886 ms and the throughput timer generates a delay of 20004077. JMeter (as of 4.0) does not support interrupting of sleeping threads, thus terminating the thread manually.