I just published the Native Spine plugin to the Marketplace.
The plugin is now in a way more stable stage, currently supporting Mac, Windows and iOS.
It is still in development and not yet ready for production builds.
How to use it
In your build.settings add:
['plugin.spine'] = {publisherId = 'com.studycat'}
Then in your code:
local spine = require("plugin.spine")
local spineObject = spine.create({
skeletonFile = system.pathForFile(path .. ".skel", system.ResourceDirectory),
atlasFile = system.pathForFile(path .. ".atlas", system.ResourceDirectory),
scale = 1.0,
listener = function(e)
-- renamed spine events to a Solar2D style:
-- phases: "began", "completed", "ended", "cancelled", "disposed" and "event"
end
})
Available methods
-- display methods
o.parent = displayGroup
o.x = number
o.y = number
o.width = number
o.height = number
o.contentWidth = number
o.contentHeight = number
o.rotation = number
o.xScale = number
o.yScale = number
o.alpha = number
o.isVisible = boolean
o:scale(x, y)
o:toFront()
o:toBack()
o:contentToLocal(x, y)
o:localToContent(x, y)
o:removeSelf()
-- spine methods
o.isActive = boolean -- read only
o:update(dt) -- In seconds, but will change to ms
o:setAnimation(trackIndex, animation, loop)
o:setDefaultMix(time) -- also seconds
o:setMix(from, to, time)
o:setToSetupPose()
o:addAnimation(trackIndex, animation, loop, delay)
o:findAnimation(animationName) -- returns true if found
o:getAllAnimations() -- returns a table of all animations
o:getAllSkins() -- returns a table of all skins
o:setSkin(skinName)
o:setAttachment(slotName, attachmentName)
o:stop()
Performance
The plugin is just way more efficient than the Lua version since it runs on C++. Some raw tests gave me these results by running 200 instances of our heaviest Animation.
Plugin
- Size: 1.5 MB β png + skel + atlas [Although json is still supported]
- Loading time: 2,592.5 ms β 13 ms / instance
- Frame rate: 21 fps
- RAM: 1.01 GB β 5.2 MB / instance
Lua Runtime
- Size: 5.3 MB β png + json + atlas
- Loading time: 72,930.1 ms β 364.6 ms / instance
- Frame rate: 3 fps
- RAM: 19.3 GB β 98.8 MB / instance
Discussion
- Should I expose the raw update methods? Currently Iβm handling all these inside a the
update()
call I guess exposing the raw could be useful for anyone who wants to customize the update cycle seeking even better performance.
spineObject:updateState(deltaTime)
spineObject:apply() -- this one triggers the events
spineObject:updateSkeleton(deltaTime) -- for the physics feature
spineObject:updateWorldTransform() -- the heavy load happens here
spineObject:render()
- Android and inverse kinematics are in the oven, what else is missing?
Resources
The plugin is open-source and you can find it at:
There is a lot of updates and improvements to be made, all contributions and suggestions are welcome. Soon I will also add a proper documentation too.