【问题标题】:Lua - nil valueLua - 无值
【发布时间】:2015-07-01 20:21:35
【问题描述】:

我从 Corona SDK 收到以下错误消息:尝试调用字段“ImageSheet”(一个 nil 值)堆栈回溯。有人能指出错误吗?

   local ISPar = {
    width = 2541,
    height = 264,
    numFrames = 7
 }
local ImageSheet = graphics.ImageSheet("Apus.png, ISPar")

local ApusSequenceData = {
  {name = "fly", frames {1,2,3,4,5,6,7}, time = 800, loopCount = 0}
  }

local Apus = display.newSrpite(ImageSheet, ApusSequenceData)
Apus.x = display.contentWidth/2
Apus.y = display.contentHeight/2
Apus:play()

【问题讨论】:

  • 应该是 graphics.newImageSheet,也缺少 = 用于表中的框架键。
  • 您还需要修正参数中的引号 ("Apus.png", ISPar) 和 display.newSprite 中的拼写错误。避免对变量使用大写的名称,因为它们可能会影响类名,否则会非常规。

标签: lua coronasdk


【解决方案1】:

你把函数名弄错了,它应该是 graphics.newImageSheet。您在调用它时也放错了引号。然后你拼错了 newSprite

这段代码应该可以工作:

local ISPar = {
    width = 2541,
    height = 264,
    numFrames = 7
}
local ImageSheet = graphics.newImageSheet("Apus.png", ISPar)

local ApusSequenceData = {{name = "fly", frames = {1,2,3,4,5,6,7}, time = 800, loopCount = 0}}

local Apus = display.newSprite(ImageSheet, ApusSequenceData)
Apus.x = display.contentWidth/2
Apus.y = display.contentHeight/2
Apus:play()

【讨论】:

  • 帧后只有“=”,否则代码完美。坦克。
  • @DFrogBinder 哎呀,很抱歉,这是我没有发现的一个错误,哈哈。很高兴我能提供帮助:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-03
  • 2014-03-14
  • 2020-12-26
  • 2015-05-21
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多