当我运行此代码时,我收到错误消息
尝试索引全局
widget
(nil
值)
local inc = 0.0
local levelUpBar, player
levelUpBar = widget.newProgressView {
left = display.contentWidth*0.5-100,
top = 300,
width = 200,
isAnimated = true }
levelUpBar:setProgress( 0 )
local function playerHit(event)
if(event.phase == "began") then
inc = inc + 0.2
if(inc > 1) then
print('level up!')
else
levelUpBar:setProgress( inc )
end
end
end
player = display.newCircle(0,0,75)
player.x = display.contentWidth*0.5
player.y = 200
player:setFillColor(0,200,0)
player:addEventListener("touch", playerHit)
答案 0 :(得分:2)
您需要添加
local widget = require("widget");
位于代码顶部