为graphics.newImageSheet动画生成帧

时间:2013-07-17 14:35:17

标签: string for-loop lua corona

我尝试构建一个为graphics.newImageSheet生成帧列表的函数。 我的函数打印看似正确的列表“1,2,3,4,5 ..”但graphics.newImageSheet拒绝它与以下错误:

WARNING: Sequence (fastRun) has an invalid index (0) that falls outside the rang
e of valid image sheet frame indices: 1 <= index <= 9.

代码:

function generateFrames(num)
    NumFrames = num
    frames = 1
    for i=2, NumFrames, 1 do
        frames = frames .. "," .. i
    end
end

sheetData = { width=32, height=40, numFrames=9, sheetContentWidth=96, sheetContentHeight=120 }

mySheet = graphics.newImageSheet( "media/enemies/enemy-" .. type .. ".png", sheetData)

generateFrames(9)

print("frames: " .. frames)

sequenceData = {
    { name = "fastRun", frames={ frames }, time=1000, loopCount = 0 }
}

1 个答案:

答案 0 :(得分:2)

请勿在{{1​​}}中使用字符串,请使用表格。

frames = {...}