Module for Quick implementation of Spine Animations

@coronasdk771 do you have any tips for implementing the multiple image sheet hack? I tried by adding an additional set of arguments to the config table for a second sheet (so like imageSheetName2, texturePackerLuaFile2, info2, sheet2),  and then adding a new skeleton:createImage function (spineHelper line 142) to deal with the second sheet, but couldn’t get it to work. Any advice/guidance on this would be really appreciated. Thanks!!

In case anyone else needs to use multiple image sheets out of texturePacker with SpineHelper, here’s what finally seems to be working for me:

Step 1: I added in additional imageSheetName and texturePackerLua to the config table:

 ------------------------------------------------- --1.- Initial Configuration of Spine Animation ------------------------------------------------- local config = config or {} local spineJson = config.spineJson -- JSON file produced by Spine (\*\*\* REQUIRED \*\*) local imageSheetName = config.imageSheetName --PNG image file produced by Texture Packer (\*\*\* REQUIRED \*\*) local imageSheetName2 = config.imageSheetName2 --\>\> ADDED FOR ADDITIONAL IMAGE SHEET local texturePackerLuaFile = config.texturePackerLuaFile --Lua file produced by Texture Packer (\*\*\* REQUIRED \*\*) local texturePackerLuaFile2 = config.texturePackerLuaFile2 --\>\> ADDED FOR ADDITIONAL IMAGE SHEET

Step2: Then I added in the additional info, sheet, and sequence data for the additional sheets:

 --------------------------------------------- --2.- Load Texture Packer Image Sheet --------------------------------------------- local info = require (texturePackerLuaFile) local info2 = require (texturePackerLuaFile2) --\>\> ADDED local sheet1 = graphics.newImageSheet ( imageSheetName, info:getSheet() ) local sheet2 = graphics.newImageSheet ( imageSheetName2, info2:getSheet() ) --\>\> ADDED local sequence1 = { start=1, count= #info:getSheet().frames } local sequence2 = { start=1, count= #info2:getSheet().frames } --\>\> ADDED

And finally I modified the skeleton:createImage function to look for the attachment name in the second sheet if the name is nil in the first sheet:

 ------------------------------------------- --3.1 Draw Skeleton with its images ------------------------------------------- function skeleton:createImage(attachment) local image -- check to see if the requested attachment is in sheet 1 if ( info:getFrameIndex ( attachment.name ) ) ~= nil then image = display.newSprite(sheet1, sequence1) image.name = attachment.name image:setFrame (info:getFrameIndex (attachment.name)) image.width, image.height = attachment.width, attachment.height end -- check to see if the requested attachment is in sheet 2 if ( info2:getFrameIndex ( attachment.name ) ) ~= nil then image = display.newSprite(sheet2, sequence2) image.name = attachment.name image:setFrame (info2:getFrameIndex (attachment.name)) image.width, image.height = attachment.width, attachment.height end return image end

Thought I’d share just in case anyone else spends 2 days totally stumped like me :slight_smile:

Hi Hector. Thanks for this awsome library. Do you plan to put it on GitHub so people can contribute back?

Thanks coronasdk771, yes good idea, let me put it in Github later tonight so everybody can contribute. I’ll post the link here when it’s ready

Regards

Hector

Hi,

there seems to be an error in spineHelper.lua

line 511

currentAnimation = state:getCurrent(0).animation.name

It some how sometimes generates a runtime error.

When I run my app it runs it changes it a few times and then it pops up. Then works again a few times.

I have 3 animations in my sprites.

I changed it to “rest” state animation so it always has that as a default. And it seems to have solved it.

This only happens on the device not on the simulator.

I checked for capitalisation, but couldn’t find any errors.

Is there somewhere I can look in my code or is this a spineHelper problem?

@Hector

awsome!

@Juf Jannie

The line you mentioned is 520 in my case. I re-downloaded SpineHelper few days ago, maybe Hector made few tweaks here and there after you got SpineHelper. It might be worth re-downloading it.

Has anyone figured out how to listen for Spine “Events” within the context of using Hector’s Spine Helper? Having some trouble figuring out exactly how to do this…

(and thanks for this module, Hector!!)

Has anyone figured out how to fix the runtime error on that “currentAnimation = state:getCurrent(0).animation.name” line in the module? For me it’s on line 522 of the module.

When I change animation with changeAnimation() I always get “Initial Animation is still running” in the console but never get runtime error. I also noticed that previous animation keeps playing for some time (2-3 secs) before transition to desired animation.

In the mean time I added remove() method because I didn’t know how to get rid of loaded testures. Improvements are welcomed :wink:

[lua]

function SpineHelper:remove(…)
    self:stopAnimation()
    for k,v in pairs(self.skeleton.images) do
        if type(self.skeleton.images[k].removeSelf) == “function” then
            self.skeleton.images[k]:removeSelf()
        end
        self.skeleton.images[k] = nil
    end        
end

[/lua]

Also added one line in initialize()

[lua]

        self.skeletonData = skeletonData
        self.skeleton = skeleton
        self.root = root
        self.stateData = stateData
        self.state = state

        sheet = nil    – sheet is no longer needed

[/lua]

Has anyone figured out how to add touch listeners to whole animation object or specified bones? It can’t get it working.

Hey guys,

My apologies for not getting back sooner. I have two good news and a bad one:

1.- I have posted the SpineHelper library along with sample codes (including Photoshop, TexturePacker files) to GitHub so everyone can contribute and make it better. You can find it here: https://github.com/CoronaDevs/CoronaSDK-Spine-Helper

2.- I also created a FREE full video course (25 lessons) that teaches you the whole process from creating and designing a character in Photoshop,  creating the ImageSheet in TexturePacker, the animation of several characters in Spine, to the whole implementation in Corona, including adding interactivity to the characters created. You can find the tutorials here https://www.youtube.com/playlist?list=PLKhvt82d5sfCE6KkM1V6Bs46GG4HOguP1

3.- Finally the bad news… I’m no longer maintaining the library as I’ve been busy with other stuff in my life, but I didn’t want to leave without giving you access to the code in GitHub and the video tutorial. Feel free to make edits or create a totally new version of my code, I’m sure you can take it to a new level

Regards

Hector

Hi Hector, thanks for putting source on GitHub and videos. Could you please add license info for SpineHelper? Without it it may be blocking use of SpineHelper in some cases. Hope the community will pick up development, will you accept any pull requests or should we use our forks?

Hi there!, sure I can add license info, any idea of what good wording I could use? I think it’d be better to let everybody to use their own fork that way they can work independently of mine

Regards,

Hector

I think MIT will be good. https://tldrlegal.com/license/mit-license

Does anyone know if it’s possible to use multipacked image sheets out of texture packer with SpineHelper?

No, SpineHelper assumes all sprites are on single sheet but you could easily hack that.

@coronasdk771 do you have any tips for implementing the multiple image sheet hack? I tried by adding an additional set of arguments to the config table for a second sheet (so like imageSheetName2, texturePackerLuaFile2, info2, sheet2),  and then adding a new skeleton:createImage function (spineHelper line 142) to deal with the second sheet, but couldn’t get it to work. Any advice/guidance on this would be really appreciated. Thanks!!

In case anyone else needs to use multiple image sheets out of texturePacker with SpineHelper, here’s what finally seems to be working for me:

Step 1: I added in additional imageSheetName and texturePackerLua to the config table:

 ------------------------------------------------- --1.- Initial Configuration of Spine Animation ------------------------------------------------- local config = config or {} local spineJson = config.spineJson -- JSON file produced by Spine (\*\*\* REQUIRED \*\*) local imageSheetName = config.imageSheetName --PNG image file produced by Texture Packer (\*\*\* REQUIRED \*\*) local imageSheetName2 = config.imageSheetName2 --\>\> ADDED FOR ADDITIONAL IMAGE SHEET local texturePackerLuaFile = config.texturePackerLuaFile --Lua file produced by Texture Packer (\*\*\* REQUIRED \*\*) local texturePackerLuaFile2 = config.texturePackerLuaFile2 --\>\> ADDED FOR ADDITIONAL IMAGE SHEET

Step2: Then I added in the additional info, sheet, and sequence data for the additional sheets:

 --------------------------------------------- --2.- Load Texture Packer Image Sheet --------------------------------------------- local info = require (texturePackerLuaFile) local info2 = require (texturePackerLuaFile2) --\>\> ADDED local sheet1 = graphics.newImageSheet ( imageSheetName, info:getSheet() ) local sheet2 = graphics.newImageSheet ( imageSheetName2, info2:getSheet() ) --\>\> ADDED local sequence1 = { start=1, count= #info:getSheet().frames } local sequence2 = { start=1, count= #info2:getSheet().frames } --\>\> ADDED

And finally I modified the skeleton:createImage function to look for the attachment name in the second sheet if the name is nil in the first sheet:

 ------------------------------------------- --3.1 Draw Skeleton with its images ------------------------------------------- function skeleton:createImage(attachment) local image -- check to see if the requested attachment is in sheet 1 if ( info:getFrameIndex ( attachment.name ) ) ~= nil then image = display.newSprite(sheet1, sequence1) image.name = attachment.name image:setFrame (info:getFrameIndex (attachment.name)) image.width, image.height = attachment.width, attachment.height end -- check to see if the requested attachment is in sheet 2 if ( info2:getFrameIndex ( attachment.name ) ) ~= nil then image = display.newSprite(sheet2, sequence2) image.name = attachment.name image:setFrame (info2:getFrameIndex (attachment.name)) image.width, image.height = attachment.width, attachment.height end return image end

Thought I’d share just in case anyone else spends 2 days totally stumped like me :slight_smile:

Amazing job with the spineHelper Hector  :lol: Million thanks for sharing it and making the video tutorials  :slight_smile:

Oh! I can´t figure this out :frowning:

I get an error:

spine-lua/AttachmentLoader.lua:51: attempt to concatenate local ‘type’ (a nil value)

/Users/Admin/Dropbox/CORONA/prosjekt/testSpine/spine-lua/AttachmentLoader.lua:51: in function ‘newAttachment’

/Users/Admin/Dropbox/CORONA/prosjekt/testSpine/spine-lua/SkeletonJson.lua:175: in function ‘readAttachment’

/Users/Admin/Dropbox/CORONA/prosjekt/testSpine/spine-lua/SkeletonJson.lua:136: in function </Users/Admin/Dropbox/CORONA/prosjekt/testSpine/spine-lua/SkeletonJson.lua:67>

(tail call): ?

/Users/Admin/Dropbox/CORONA/prosjekt/testSpine/SpineHelper.lua:130: in function ‘initialize’

/Users/Admin/Dropbox/CORONA/prosjekt/testSpine/SpineHelper.lua:75: in function ‘new’

 

I figure it has to be with my skeleton-file?! I tried using Hectors tutorial files and they work fine  :wacko: I don´t understand. I do everything exactly as Hector says.

Ok! I just deleted line 51 in spine-lua/AttachementLoader.lua and now it works fine :wink:

This line:

–error(“Unknown attachment type: " … type … " (” … name … “)”)