我在嘗試重新加載場景時遇到了一些麻煩。嘗試在重新加載場景時調用方法「插入」(一個零值)
在我的計劃中,用戶都能夠得出一個符合自己的手指(這是在iOS/Android應用程序),和它的作品不錯,但,當我嘗試重新加載場景,控制檯返回
「嘗試索引字段‘父’(一個零值)」
在管線78
我已經用於執行(在這種情況下回放)「的DrawLine」和重裝功能的代碼是
local lines = {}
local lineGroup = display.newGroup()
local prevX,prevY
local isDrawing = true
local i = 1
local function distanceBetween(x1, y1, x2, y2)
local dist_x = x2 - x1
local dist_y = y2 - y1
local distanceBetween = math.sqrt((dist_x*dist_x) + (dist_y*dist_y))
return distanceBetween
end
local function drawLine(e)
if(e.phase == "began") then
for i = #lines, 1, -1 do
if (lines[i]) then
if (lines[i].parent) then
lines[i].parent:remove(lines[i])
end
lines[i] = nil
end
end
lines = {}
line_number = 100
prevX = e.x
prevY = e.y
isDrawing = true
elseif(e.phase == "moved") then
local distance = distanceBetween(prevX, prevY, e.x, e.y)
if(isDrawing and distance < 100) then
if(lines[i]) then lineGroup:remove(i) end
lines[i] = display.newLine(prevX, prevY, e.x, e.y)
lines[i]:setColor(255, 255, 0)
lines[i].width = 3
lines[i].myName = "lines"
if(lines[i].y < 400) then
for i = #lines, 1, -1 do
if (lines[i]) then
if (lines[i].parent) then
lines[i].parent:remove(lines[i])
end
lines[i] = nil
end
end
end
local dist_x = e.x - prevX
local dist_y = e.y - prevY
physics.addBody(lines[i], "static",
{ density = 1, friction = 0.5, bounce =
-0.8, shape = {0, 0, dist_x, dist_y, 0, 0} })
lineGroup:insert(lines[i])
end
elseif(e.phase == "ended") then
isDrawing = true
end
return lineGroup
end
Runtime:addEventListener("touch",drawLine)
其中線78:
lineGroup:insert(lines[i])
我重新使用
local replayBTN = display.newImageRect("images/replay.png", 25, 25)
replayBTN.alpha = 1
replayBTN.x = _W/2
replayBTN.y = _H/2
localGroup:insert(replayBTN)
function replay(event)
director:changeScene("game")
return true
end
replayBTN:addEventListener("touch", replay)
我怎樣才能解決我的問題,我的遊戲?謝謝;)
你得到了一個完整的堆棧跟蹤錯誤? – greatwolf