From 2c3453f4dd1c888d03a2c52343a5979f3e029b69 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sat, 27 Apr 2013 13:48:36 +0200 Subject: [PATCH] Fixed spine-corona skins, slots. --- spine-corona/main.lua | 13 +++++++++---- spine-corona/spine-corona/spine.lua | 16 ++++++++-------- spine-lua/Skeleton.lua | 15 ++++++++++----- spine-lua/SkeletonJson.lua | 2 +- spine-lua/Slot.lua | 4 +++- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/spine-corona/main.lua b/spine-corona/main.lua index b302fe63b..7e4df5346 100644 --- a/spine-corona/main.lua +++ b/spine-corona/main.lua @@ -1,21 +1,25 @@ local spine = require "spine-corona.spine" +--local name = "goblins" +local name = "spineboy" + local json = spine.SkeletonJson.new() json.scale = 1 -local skeletonData = json:readSkeletonDataFile("data/spineboy.json") +local skeletonData = json:readSkeletonDataFile("data/" .. name .. "/" .. name .. ".json") local walkAnimation = skeletonData:findAnimation("walk") local skeleton = spine.Skeleton.new(skeletonData) function skeleton:createImage (attachment) -- Customize where images are loaded. - return display.newImage("data/" .. attachment.name .. ".png") + return display.newImage("data/" .. name .. "/" .. attachment.name .. ".png") end -skeleton.x = 150 -skeleton.y = 325 +skeleton.group.x = 150 +skeleton.group.y = 325 skeleton.flipX = false skeleton.flipY = false skeleton.debug = true -- Omit or set to false to not draw debug lines on top of the images. +if name == "goblins" then skeleton:setSkin("goblingirl") end skeleton:setToBindPose() local lastTime = 0 @@ -31,3 +35,4 @@ Runtime:addEventListener("enterFrame", function (event) walkAnimation:apply(skeleton, animationTime, true) skeleton:updateWorldTransform() end) + diff --git a/spine-corona/spine-corona/spine.lua b/spine-corona/spine-corona/spine.lua index 4d3a714d9..427629ec0 100644 --- a/spine-corona/spine-corona/spine.lua +++ b/spine-corona/spine-corona/spine.lua @@ -59,8 +59,8 @@ spine.Skeleton.new_super = spine.Skeleton.new function spine.Skeleton.new (skeletonData, group) -- Skeleton extends a group. local self = spine.Skeleton.new_super(skeletonData) - self = spine.utils.copy(self, group or display.newGroup()) - + self.group = group or display.newGroup() + -- createImage can customize where images are found. function self:createImage (attachment) return display.newImage(attachment.name .. ".png") @@ -76,12 +76,12 @@ function spine.Skeleton.new (skeletonData, group) for i,slot in ipairs(self.drawOrder) do local attachment = slot.attachment - local image = images[attachment] + local image = images[slot] if not attachment then -- Attachment is gone, remove the image. if image then image:removeSelf() - images[attachment] = nil + images[slot] = nil end else -- Create new image. @@ -95,7 +95,7 @@ function spine.Skeleton.new (skeletonData, group) print("Error creating image: " .. attachment.name) image = spine.Skeleton.failed end - images[attachment] = image + images[slot] = image end -- Position image based on attachment and bone. if image ~= spine.Skeleton.failed then @@ -113,7 +113,7 @@ function spine.Skeleton.new (skeletonData, group) image.rotation = -image.rotation end image:setFillColor(slot.r, slot.g, slot.b, slot.a) - self:insert(image) + self.group:insert(image) end end end @@ -137,13 +137,13 @@ function spine.Skeleton.new (skeletonData, group) bone.line.yScale = 1 end bone.line:setColor(255, 0, 0) - self:insert(bone.line) + self.group:insert(bone.line) if not bone.circle then bone.circle = display.newCircle(0, 0, 3) end bone.circle.x = bone.worldX bone.circle.y = -bone.worldY bone.circle:setFillColor(0, 255, 0) - self:insert(bone.circle) + self.group:insert(bone.circle) end end end diff --git a/spine-lua/Skeleton.lua b/spine-lua/Skeleton.lua index c20e3d02b..45c7c3929 100644 --- a/spine-lua/Skeleton.lua +++ b/spine-lua/Skeleton.lua @@ -100,20 +100,25 @@ function Skeleton.new (skeletonData) if not attachmentName then error("attachmentName cannot be nil.", 2) end local slotIndex = self.data:findSlotIndex(slotName) if slotIndex == -1 then error("Slot not found: " .. slotName, 2) end - if self.skin then return self.skin:getAttachment(slotIndex, attachmentName) end - if self.data.defaultSkin then - local attachment = self.data.defaultSkin:getAttachment(slotIndex, attachmentName) + if self.skin then + local attachment = self.skin:getAttachment(slotIndex, attachmentName) if attachment then return attachment end end + if self.data.defaultSkin then + return self.data.defaultSkin:getAttachment(slotIndex, attachmentName) + end return nil end function self:setAttachment (slotName, attachmentName) if not slotName then error("slotName cannot be nil.", 2) end - if not attachmentName then error("attachmentName cannot be nil.", 2) end for i,slot in ipairs(self.slots) do if slot.data.name == slotName then - slot:setAttachment(self:getAttachment(slotName, attachmentName)) + if not attachmentName then + slot:setAttachment(nil) + else + slot:setAttachment(self:getAttachment(slotName, attachmentName)) + end return end end diff --git a/spine-lua/SkeletonJson.lua b/spine-lua/SkeletonJson.lua index 58856aa0a..f820a019f 100644 --- a/spine-lua/SkeletonJson.lua +++ b/spine-lua/SkeletonJson.lua @@ -241,7 +241,7 @@ function SkeletonJson.new (attachmentLoader) for i,valueMap in ipairs(values) do local time = valueMap["time"] local attachmentName = valueMap["name"] - if attachmentName == json.null then attachmentName = nil end + if not attachmentName then attachmentName = nil end timeline:setKeyframe(keyframeIndex, time, attachmentName) keyframeIndex = keyframeIndex + 1 end diff --git a/spine-lua/Slot.lua b/spine-lua/Slot.lua index a5a1a313e..bde8d8f44 100644 --- a/spine-lua/Slot.lua +++ b/spine-lua/Slot.lua @@ -61,7 +61,9 @@ function Slot.new (slotData, skeleton, bone) self:setColor(data.r, data.g, data.b, data.a) local attachment - if data.attachmentName then attachment = self.skeleton:getAttachment(data.name, data.attachmentName) end + if data.attachmentName then + attachment = self.skeleton:getAttachment(data.name, data.attachmentName) + end self:setAttachment(attachment) end