[lua] Added mix-and-match example. See #1375.

This commit is contained in:
badlogic 2019-06-13 16:49:32 +02:00
parent 2946cec9d1
commit ee32f30545
3 changed files with 38 additions and 0 deletions

View File

@ -102,6 +102,23 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
--skeleton.vertexEffect = spine.JitterEffect.new(5, 5) --skeleton.vertexEffect = spine.JitterEffect.new(5, 5)
skeleton.vertexEffect = swirl skeleton.vertexEffect = swirl
animationState:setAnimationByName(0, animation, true) animationState:setAnimationByName(0, animation, true)
elseif jsonFile == "mix-and-match-pro.json" then
-- Create a new skin, by mixing and matching other skins
-- that fit together. Items making up the girl are individual
-- skins. Using the skin API, a new skin is created which is
-- a combination of all these individual item skins.
local skin = spine.Skin.new("mix-and-match")
skin:addSkin(skeletonData:findSkin("skin-base"))
skin:addSkin(skeletonData:findSkin("nose/short"))
skin:addSkin(skeletonData:findSkin("eyes/eyelids-girly"))
skin:addSkin(skeletonData:findSkin("eyes/violet"))
skin:addSkin(skeletonData:findSkin("hair/brown"))
skin:addSkin(skeletonData:findSkin("clothes/hoodie-orange"))
skin:addSkin(skeletonData:findSkin("legs/pants-jeans"))
skin:addSkin(skeletonData:findSkin("accessories/bag"))
skin:addSkin(skeletonData:findSkin("accessories/hat-red-yellow"))
skeleton:setSkinByReference(skin)
animationState:setAnimationByName(0, animation, true)
else else
animationState:setAnimationByName(0, animation, true) animationState:setAnimationByName(0, animation, true)
end end
@ -110,6 +127,7 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
return { skeleton = skeleton, state = animationState } return { skeleton = skeleton, state = animationState }
end end
table.insert(skeletons, loadSkeleton("mix-and-match.atlas", "mix-and-match-pro.json", 240, 300, 0.3, "dance"))
table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy-pro.json", 240, 300, 0.4, "walk")) table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy-pro.json", 240, 300, 0.4, "walk"))
table.insert(skeletons, loadSkeleton("stretchyman.atlas", "stretchyman-stretchy-ik-pro.json", 40, 300, 0.5, "sneak")) table.insert(skeletons, loadSkeleton("stretchyman.atlas", "stretchyman-stretchy-ik-pro.json", 40, 300, 0.5, "sneak"))
table.insert(skeletons, loadSkeleton("coin.atlas", "coin-pro.json", 240, 160, 0.4, "animation")) table.insert(skeletons, loadSkeleton("coin.atlas", "coin-pro.json", 240, 160, 0.4, "animation"))

View File

@ -66,6 +66,24 @@ function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y)
-- skeleton.vertexEffect = spine.JitterEffect.new(10, 10) -- skeleton.vertexEffect = spine.JitterEffect.new(10, 10)
end end
if jsonFile == "mix-and-match-pro" then
-- Create a new skin, by mixing and matching other skins
-- that fit together. Items making up the girl are individual
-- skins. Using the skin API, a new skin is created which is
-- a combination of all these individual item skins.
local skin = spine.Skin.new("mix-and-match")
skin:addSkin(skeletonData:findSkin("skin-base"))
skin:addSkin(skeletonData:findSkin("nose/short"))
skin:addSkin(skeletonData:findSkin("eyes/eyelids-girly"))
skin:addSkin(skeletonData:findSkin("eyes/violet"))
skin:addSkin(skeletonData:findSkin("hair/brown"))
skin:addSkin(skeletonData:findSkin("clothes/hoodie-orange"))
skin:addSkin(skeletonData:findSkin("legs/pants-jeans"))
skin:addSkin(skeletonData:findSkin("accessories/bag"))
skin:addSkin(skeletonData:findSkin("accessories/hat-red-yellow"))
skeleton:setSkinByReference(skin)
end
-- set some event callbacks -- set some event callbacks
state.onStart = function (entry) state.onStart = function (entry)
print(entry.trackIndex.." start: "..entry.animation.name) print(entry.trackIndex.." start: "..entry.animation.name)
@ -95,6 +113,7 @@ end
function love.load(arg) function love.load(arg)
if arg[#arg] == "-debug" then require("mobdebug").start() end if arg[#arg] == "-debug" then require("mobdebug").start() end
skeletonRenderer = spine.SkeletonRenderer.new(true) skeletonRenderer = spine.SkeletonRenderer.new(true)
table.insert(skeletons, loadSkeleton("mix-and-match-pro", "mix-and-match", "dance", nil, 0.5, 400, 500))
table.insert(skeletons, loadSkeleton("spineboy-pro", "spineboy", "walk", nil, 0.5, 400, 500)) table.insert(skeletons, loadSkeleton("spineboy-pro", "spineboy", "walk", nil, 0.5, 400, 500))
table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.3, 200, 500)) table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.3, 200, 500))
table.insert(skeletons, loadSkeleton("coin-pro", "coin", "animation", nil, 0.5, 400, 300)) table.insert(skeletons, loadSkeleton("coin-pro", "coin", "animation", nil, 0.5, 400, 300))

View File

@ -27,6 +27,7 @@
-- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
local utils = require "spine-lua.utils"
local Bone = require "spine-lua.Bone" local Bone = require "spine-lua.Bone"
local Slot = require "spine-lua.Slot" local Slot = require "spine-lua.Slot"
local IkConstraint = require "spine-lua.IkConstraint" local IkConstraint = require "spine-lua.IkConstraint"