我今天刚刚开始学习Lua。我一直在做coronalabs.com网站上的教程......我尝试着将弹跳气球轻击到小行星游戏的场景模板中,以适应第一个练习。有人能告诉我我是如何“尝试索引价值”吗?尝试索引upvalue
local composer = require("composer")
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
local physics = require("physics")
physics.start()
local tapCount = 0
local platform
local balloon
local tapText
local function pushBalloon()
balloon:applyLinearImpulse(0, -0.75, balloon.x, balloon.y)
tapCount = tapCount + 1
tapText.text = tapCount
end
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create(event)
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
physics.pause()
local background = display.newImageRect("background.png", 360, 570)
background.x = display.contentCenterX
background.y = display.contentCenterY
local platform = display.newImageRect("platform.png", 300, 50)
platform.x = display.contentCenterX
platform.y = display.contentHeight-25
local balloon = display.newImageRect("balloon.png", 112, 112)
balloon.x = display.contentCenterX
balloon.y = display.contentCenterY
balloon.alpha = 0.8
local tapText = display.newText(tapCount, display.contentCenterX, 20, native.systemFont, 40)
tapText:setFillColor(0, 0, 0)
physics.addBody(platform, "static")
physics.addBody(balloon, "dynamic", { radius=50, bounce=0.6 })
balloon:addEventListener("tap", pushBalloon)
end
-- show()
function scene:show(event)
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
-- Code here runs when the scene is still off screen (but is about to come on screen)
elseif (phase == "did") then
-- Code here runs when the scene is entirely on screen
physics.start()
end
end
-- hide()
function scene:hide(event)
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
-- Code here runs when the scene is on screen (but is about to go off screen)
elseif (phase == "did") then
-- Code here runs immediately after the scene goes entirely off screen
physics.pause()
end
end
-- destroy()
function scene:destroy(event)
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener("create", scene)
scene:addEventListener("show", scene)
scene:addEventListener("hide", scene)
scene:addEventListener("destroy", scene)
-- -----------------------------------------------------------------------------------
return scene
在哪一行#错误提出? –
上面的代码在我的模拟器中不会产生任何错误。 – ldurniat