1
我會嘗試儘可能簡潔與我的問題。科羅娜SDK數組索引超過數組邊界的,建議需要
首先,文件是:
block.lua
base.lua
main.lua
在block.lua我創建塊,添加碰撞檢測和清理代碼。 在base.lua中,我創建了一個由4列和10行組成的基礎。共40個街區。 在main.lua中,我創建了4個由base.class構成的基地。一旦比賽開始
所有工作正常。 我刪除了基地,並再次打電話給他們上2級 他們創造自己確定的,但 當敵人被再次破壞,基地重建,我得到一個:
array index 1 is beyond array bounds:1..1
- 所有一路攀升中場休息
array index 800 is beyond array bounds:1..159
它就會建立基地和繼續下去,直到敵人被破壞,做同樣的再次開始:
array index 800 is beyond array bounds:1..159
- 一路中場休息
array index 4000 is beyond array bounds:1..159
blockGroup:insert(blockNum,self.block)
現在我看不到什麼毛病類中的終端點我在block.lua行,我已經看過,並用Google搜索幾個小時,但都無濟於事。 我真的很感謝在這裏指導我的幫助之手。 我曾嘗試重寫「清理」等,但沒有喜悅。 我留下了幾註釋掉位在那裏,並去掉了一些無關緊要的東西。 我張貼相關的代碼如下:
--MAIN.LUA--
function gameOver()
Runtime:removeEventListener("enterFrame", onEnterFrame)
Runtime:removeEventListener("enterFrame", movePlayer)
layers:removeSelf()
layers = nil
enemyCount = 0
for i = 1,#allEnemys do
timer.cancel(allEnemys[i].clock)
Runtime:removeEventListener("enterFrame", allEnemys[i])
display.remove(allEnemys[i].image)
allEnemys[i].image=nil
end
allEnemys=nil
cleanupBlocks()
end
----------------------------------------------------------------------
-- LEVEL UP --
----------------------------------------------------------------------
function levelUp(level)
enemyCount = 0
local enemys = require("modules.enemy")
if allEnemys ~= nil then
for i = 1,#allEnemys do
timer.cancel(allEnemys[i].clock)
Runtime:removeEventListener("enterFrame", allEnemys[i])
display.remove(allEnemys[i].image)
allEnemys[i].image=nil
end
end
allEnemys=nil
cleanupBlocks()
levels()
end
----------------------------------------------------------------------
-- LEVELS --
----------------------------------------------------------------------
function levels(level)
function createInvader(x, y, row)
for j = 1, 2 do
for i = 1, 2 do
if allEnemys == nil then
allEnemys = {}
else
enemysCount=#allEnemys
end
allEnemys[#allEnemys + 1] = enemys:new()
allEnemys[#allEnemys ]:init(i * 60, j * 70 + 70,j)
allEnemys[#allEnemys ]:start()
end
end
end
createInvader()
--[[function createBases1()
local base = require("modules.base")
for i = 1, 4 do
base:new()
base:init(i * 180 - 130, 850)
end
end ]]--
createBases()
end
--BLOCK.LUA--
local block = {}
local block_mt = { __index = block}
local scene = scene
local blockGroup = display.newGroup()
local blockNum = 0
function block:new() -- constructor
local group = {}
return setmetatable(group, block_mt)
end
function block:init(xloc,yloc) --initializer
-- Create attributes
self.block = display.newRect(xloc,yloc,10,10)
self.block:setFillColor (2, 255, 14 )
blockNum = blockNum + 1
blockGroup:insert(blockNum,self.block)
local blockCollisionFilter = { categoryBits = 128, maskBits = 387}
physics.addBody(self.block, "static", {filter = blockCollisionFilter})
self.count = 1
end
function cleanupBlocks()
--[[ print(blockNum, blockGroup.numChildren)
for i=1,blockGroup.numChildren do
blockGroup[1]:removeSelf()
blockGroup[1] = nil
end ]]--
print(blockNum, blockGroup.numChildren)
while blockGroup.numChildren>0 do
display.remove(blockGroup[1])
blockGroup[1]=nil
end
end
function block:start()
--- Create Listeneres
self.block:addEventListener("collision", self)
scene:addEventListener('base_block_event', self)
end
return block
--BASE.LUA--
local base = {}
local base_mt = { __index = base}
local scene = scene
local block = require("modules.block")
function base:new() -- constructor
local group = {}
return setmetatable(group, base_mt)
end
function base:init(xloc, yloc) --initializer
-- Create attributes
local base
for j = 1, 4 do
for i = 1, 10 do
base = block:new()
base:init(xloc+i * 10,yloc+j * 10)
base:start()
end
end
end
return base