Cant Open Lua Scene Spine Test Cocos2dx v4

216 views Asked by At

im using cocos Lua v4. and im looking how to create spine in Lua. But unfortunately, when im open Lua Test in Spine section. Its not showing spine, i got this error

attempt to index global ‘sp’ (a nil value) Lua Test

Lua Error

Its that a bug ? if is not, how can i fix it so i can create spine in Lua ? Thanks

Edit 1 Here how to make spine in 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

in 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,
}
1

There are 1 answers

0
Chris On

No.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)

No.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)

No.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)