1

我正在使用 cocos Lua v4。我正在寻找如何在 Lua 中创建脊椎。但不幸的是,当我在 Spine 部分打开 Lua Test 时。它没有显示脊椎,我收到了这个错误

尝试索引全局“sp”(零值) Lua 测试

Lua 错误

这是一个错误吗?如果不是,我该如何修复它以便我可以在 Lua 中创建脊椎?谢谢

编辑 1 这里如何在 cocos lua v4 中制作脊椎

require "cocos.spine.SpineConstants"

function SpineTestLayerNormal:init()
  local skeletonNode = sp.SkeletonAnimation:create("spine/spineboy-ess.json", "spine/spineboy.atlas", 0.6)
end

cocos/spine/SpineConstants

if nil == sp then
    return
end

sp.EventType =
{
    ANIMATION_START = 0, 
    ANIMATION_INTERRUPT = 1,
    ANIMATION_END = 2, 
    ANIMATION_COMPLETE = 3,
    ANIMATION_DISPOSE = 4,
    ANIMATION_EVENT = 5,
}
4

1 回答 1

0

1号

local spineSP = sp.SkeletonAnimation:createWithJsonFile("tank/tank-pro.json","tank/tank-pma.atlas")
spineSP:pos(display.width / 2, display.height / 2):addTo(self)
spineSP:setAnimation(0, "drive", true)

2号

local spineSP = sp.SkeletonAnimation:createWithBinaryFile("tank/tank-pro.skel", "tank/tank-pma.atlas")
spineSP:pos(display.width / 2, display.height / 2):addTo(self)
spineSP:setAnimation(0, "drive", true)

3号

-- 创建缓存,全局变量以便于不被释放
cachedData = sp.SkeletonData:create("tank/tank-pro.json", "tank/tank.atlas")
local spineSP = sp.SkeletonAnimation:createWithData(cachedData)
spineSP:pos(display.width / 2, display.height / 2):addTo(self)
spineSP:setAnimation(0, "drive", true)
-- 测试从一个 sp.SkeletonData 多次创建
self:performWithDelay(function()
    local spineSP = sp.SkeletonAnimation:createWithData(cachedData)
    spineSP:pos(display.width / 2, 100):addTo(self)
    spineSP:setAnimation(0, "drive", true)
end, 1)
于 2021-07-26T14:14:03.003 回答