mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Fixed spine-corona skins, slots.
This commit is contained in:
parent
5ed819ba84
commit
2c3453f4dd
@ -1,21 +1,25 @@
|
|||||||
|
|
||||||
local spine = require "spine-corona.spine"
|
local spine = require "spine-corona.spine"
|
||||||
|
|
||||||
|
--local name = "goblins"
|
||||||
|
local name = "spineboy"
|
||||||
|
|
||||||
local json = spine.SkeletonJson.new()
|
local json = spine.SkeletonJson.new()
|
||||||
json.scale = 1
|
json.scale = 1
|
||||||
local skeletonData = json:readSkeletonDataFile("data/spineboy.json")
|
local skeletonData = json:readSkeletonDataFile("data/" .. name .. "/" .. name .. ".json")
|
||||||
local walkAnimation = skeletonData:findAnimation("walk")
|
local walkAnimation = skeletonData:findAnimation("walk")
|
||||||
|
|
||||||
local skeleton = spine.Skeleton.new(skeletonData)
|
local skeleton = spine.Skeleton.new(skeletonData)
|
||||||
function skeleton:createImage (attachment)
|
function skeleton:createImage (attachment)
|
||||||
-- Customize where images are loaded.
|
-- Customize where images are loaded.
|
||||||
return display.newImage("data/" .. attachment.name .. ".png")
|
return display.newImage("data/" .. name .. "/" .. attachment.name .. ".png")
|
||||||
end
|
end
|
||||||
skeleton.x = 150
|
skeleton.group.x = 150
|
||||||
skeleton.y = 325
|
skeleton.group.y = 325
|
||||||
skeleton.flipX = false
|
skeleton.flipX = false
|
||||||
skeleton.flipY = false
|
skeleton.flipY = false
|
||||||
skeleton.debug = true -- Omit or set to false to not draw debug lines on top of the images.
|
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()
|
skeleton:setToBindPose()
|
||||||
|
|
||||||
local lastTime = 0
|
local lastTime = 0
|
||||||
@ -31,3 +35,4 @@ Runtime:addEventListener("enterFrame", function (event)
|
|||||||
walkAnimation:apply(skeleton, animationTime, true)
|
walkAnimation:apply(skeleton, animationTime, true)
|
||||||
skeleton:updateWorldTransform()
|
skeleton:updateWorldTransform()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@ -59,8 +59,8 @@ spine.Skeleton.new_super = spine.Skeleton.new
|
|||||||
function spine.Skeleton.new (skeletonData, group)
|
function spine.Skeleton.new (skeletonData, group)
|
||||||
-- Skeleton extends a group.
|
-- Skeleton extends a group.
|
||||||
local self = spine.Skeleton.new_super(skeletonData)
|
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.
|
-- createImage can customize where images are found.
|
||||||
function self:createImage (attachment)
|
function self:createImage (attachment)
|
||||||
return display.newImage(attachment.name .. ".png")
|
return display.newImage(attachment.name .. ".png")
|
||||||
@ -76,12 +76,12 @@ function spine.Skeleton.new (skeletonData, group)
|
|||||||
|
|
||||||
for i,slot in ipairs(self.drawOrder) do
|
for i,slot in ipairs(self.drawOrder) do
|
||||||
local attachment = slot.attachment
|
local attachment = slot.attachment
|
||||||
local image = images[attachment]
|
local image = images[slot]
|
||||||
if not attachment then
|
if not attachment then
|
||||||
-- Attachment is gone, remove the image.
|
-- Attachment is gone, remove the image.
|
||||||
if image then
|
if image then
|
||||||
image:removeSelf()
|
image:removeSelf()
|
||||||
images[attachment] = nil
|
images[slot] = nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Create new image.
|
-- Create new image.
|
||||||
@ -95,7 +95,7 @@ function spine.Skeleton.new (skeletonData, group)
|
|||||||
print("Error creating image: " .. attachment.name)
|
print("Error creating image: " .. attachment.name)
|
||||||
image = spine.Skeleton.failed
|
image = spine.Skeleton.failed
|
||||||
end
|
end
|
||||||
images[attachment] = image
|
images[slot] = image
|
||||||
end
|
end
|
||||||
-- Position image based on attachment and bone.
|
-- Position image based on attachment and bone.
|
||||||
if image ~= spine.Skeleton.failed then
|
if image ~= spine.Skeleton.failed then
|
||||||
@ -113,7 +113,7 @@ function spine.Skeleton.new (skeletonData, group)
|
|||||||
image.rotation = -image.rotation
|
image.rotation = -image.rotation
|
||||||
end
|
end
|
||||||
image:setFillColor(slot.r, slot.g, slot.b, slot.a)
|
image:setFillColor(slot.r, slot.g, slot.b, slot.a)
|
||||||
self:insert(image)
|
self.group:insert(image)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -137,13 +137,13 @@ function spine.Skeleton.new (skeletonData, group)
|
|||||||
bone.line.yScale = 1
|
bone.line.yScale = 1
|
||||||
end
|
end
|
||||||
bone.line:setColor(255, 0, 0)
|
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
|
if not bone.circle then bone.circle = display.newCircle(0, 0, 3) end
|
||||||
bone.circle.x = bone.worldX
|
bone.circle.x = bone.worldX
|
||||||
bone.circle.y = -bone.worldY
|
bone.circle.y = -bone.worldY
|
||||||
bone.circle:setFillColor(0, 255, 0)
|
bone.circle:setFillColor(0, 255, 0)
|
||||||
self:insert(bone.circle)
|
self.group:insert(bone.circle)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -100,20 +100,25 @@ function Skeleton.new (skeletonData)
|
|||||||
if not attachmentName then error("attachmentName cannot be nil.", 2) end
|
if not attachmentName then error("attachmentName cannot be nil.", 2) end
|
||||||
local slotIndex = self.data:findSlotIndex(slotName)
|
local slotIndex = self.data:findSlotIndex(slotName)
|
||||||
if slotIndex == -1 then error("Slot not found: " .. slotName, 2) end
|
if slotIndex == -1 then error("Slot not found: " .. slotName, 2) end
|
||||||
if self.skin then return self.skin:getAttachment(slotIndex, attachmentName) end
|
if self.skin then
|
||||||
if self.data.defaultSkin then
|
local attachment = self.skin:getAttachment(slotIndex, attachmentName)
|
||||||
local attachment = self.data.defaultSkin:getAttachment(slotIndex, attachmentName)
|
|
||||||
if attachment then return attachment end
|
if attachment then return attachment end
|
||||||
end
|
end
|
||||||
|
if self.data.defaultSkin then
|
||||||
|
return self.data.defaultSkin:getAttachment(slotIndex, attachmentName)
|
||||||
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function self:setAttachment (slotName, attachmentName)
|
function self:setAttachment (slotName, attachmentName)
|
||||||
if not slotName then error("slotName cannot be nil.", 2) end
|
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
|
for i,slot in ipairs(self.slots) do
|
||||||
if slot.data.name == slotName then
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -241,7 +241,7 @@ function SkeletonJson.new (attachmentLoader)
|
|||||||
for i,valueMap in ipairs(values) do
|
for i,valueMap in ipairs(values) do
|
||||||
local time = valueMap["time"]
|
local time = valueMap["time"]
|
||||||
local attachmentName = valueMap["name"]
|
local attachmentName = valueMap["name"]
|
||||||
if attachmentName == json.null then attachmentName = nil end
|
if not attachmentName then attachmentName = nil end
|
||||||
timeline:setKeyframe(keyframeIndex, time, attachmentName)
|
timeline:setKeyframe(keyframeIndex, time, attachmentName)
|
||||||
keyframeIndex = keyframeIndex + 1
|
keyframeIndex = keyframeIndex + 1
|
||||||
end
|
end
|
||||||
|
|||||||
@ -61,7 +61,9 @@ function Slot.new (slotData, skeleton, bone)
|
|||||||
self:setColor(data.r, data.g, data.b, data.a)
|
self:setColor(data.r, data.g, data.b, data.a)
|
||||||
|
|
||||||
local attachment
|
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)
|
self:setAttachment(attachment)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user