소스 검색

Fixed spine-corona skins, slots.

NathanSweet 12 년 전
부모
커밋
2c3453f4dd
5개의 변경된 파일31개의 추가작업 그리고 19개의 파일을 삭제
  1. 9 4
      spine-corona/main.lua
  2. 8 8
      spine-corona/spine-corona/spine.lua
  3. 10 5
      spine-lua/Skeleton.lua
  4. 1 1
      spine-lua/SkeletonJson.lua
  5. 3 1
      spine-lua/Slot.lua

+ 9 - 4
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)
+

+ 8 - 8
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

+ 10 - 5
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

+ 1 - 1
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

+ 3 - 1
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