mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 18:56:54 +08:00
remove findslot from skeleton and make it into a table, for faster lookups
This commit is contained in:
parent
306f394100
commit
d69f514681
@ -36,7 +36,7 @@ function Animation.new (name, timelines, duration)
|
|||||||
function self:apply (skeleton, time, loop)
|
function self:apply (skeleton, time, loop)
|
||||||
if not skeleton then error("skeleton cannot be nil.", 2) end
|
if not skeleton then error("skeleton cannot be nil.", 2) end
|
||||||
|
|
||||||
if loop and duration > 0 then time = time % duration end
|
if loop and duration then time = time % duration end
|
||||||
|
|
||||||
for i,timeline in ipairs(self.timelines) do
|
for i,timeline in ipairs(self.timelines) do
|
||||||
timeline:apply(skeleton, time, 1)
|
timeline:apply(skeleton, time, 1)
|
||||||
@ -46,7 +46,7 @@ function Animation.new (name, timelines, duration)
|
|||||||
function self:mix (skeleton, time, loop, alpha)
|
function self:mix (skeleton, time, loop, alpha)
|
||||||
if not skeleton then error("skeleton cannot be nil.", 2) end
|
if not skeleton then error("skeleton cannot be nil.", 2) end
|
||||||
|
|
||||||
if loop and duration > 0 then time = time % duration end
|
if loop and duration then time = time % duration end
|
||||||
|
|
||||||
for i,timeline in ipairs(self.timelines) do
|
for i,timeline in ipairs(self.timelines) do
|
||||||
timeline:apply(skeleton, time, alpha)
|
timeline:apply(skeleton, time, alpha)
|
||||||
@ -371,11 +371,11 @@ function Animation.ColorTimeline.new ()
|
|||||||
local g = lastFrameG + (frames[frameIndex + FRAME_G] - lastFrameG) * percent
|
local g = lastFrameG + (frames[frameIndex + FRAME_G] - lastFrameG) * percent
|
||||||
local b = lastFrameB + (frames[frameIndex + FRAME_B] - lastFrameB) * percent
|
local b = lastFrameB + (frames[frameIndex + FRAME_B] - lastFrameB) * percent
|
||||||
local a = lastFrameA + (frames[frameIndex + FRAME_A] - lastFrameA) * percent
|
local a = lastFrameA + (frames[frameIndex + FRAME_A] - lastFrameA) * percent
|
||||||
if alpha < 1 then
|
--if alpha < 1 then
|
||||||
slot:setColor(slot.r + (r - slot.r) * alpha, slot.g + (g - slot.g) * alpha, slot.b + (b - slot.b) * alpha, slot.a + (a - slot.a) * alpha)
|
-- slot:setColor(slot.r + (r - color.r) * alpha, slot.g + (g - color.g) * alpha, slot.b + (b - color.b) * alpha, slot.a + (a - color.a) * alpha)
|
||||||
else
|
--else
|
||||||
slot:setColor(r, g, b, a)
|
slot:setColor(r, g, b, a)
|
||||||
end
|
--end
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
@ -415,7 +415,7 @@ function Animation.AttachmentTimeline.new ()
|
|||||||
local attachmentName = self.attachmentNames[frameIndex]
|
local attachmentName = self.attachmentNames[frameIndex]
|
||||||
local attachment
|
local attachment
|
||||||
if attachmentName then attachment = skeleton:getAttachment(self.slotName, attachmentName) end
|
if attachmentName then attachment = skeleton:getAttachment(self.slotName, attachmentName) end
|
||||||
skeleton:findSlot(self.slotName):setAttachment(attachment)
|
skeleton.slotsByName[self.slotName]:setAttachment(attachment)
|
||||||
end
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|||||||
@ -35,6 +35,7 @@ function Skeleton.new (skeletonData)
|
|||||||
data = skeletonData,
|
data = skeletonData,
|
||||||
bones = {},
|
bones = {},
|
||||||
slots = {},
|
slots = {},
|
||||||
|
slotsByName = {},
|
||||||
drawOrder = {}
|
drawOrder = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,14 +74,6 @@ function Skeleton.new (skeletonData)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function self:findSlot (slotName)
|
|
||||||
if not slotName then error("slotName cannot be nil.", 2) end
|
|
||||||
for i,slot in ipairs(self.slots) do
|
|
||||||
if slot.data.name == slotName then return slot end
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function self:setSkin (skinName)
|
function self:setSkin (skinName)
|
||||||
local newSkin
|
local newSkin
|
||||||
if skinName then
|
if skinName then
|
||||||
@ -147,6 +140,7 @@ function Skeleton.new (skeletonData)
|
|||||||
local bone = self.bones[spine.utils.indexOf(skeletonData.bones, slotData.boneData)]
|
local bone = self.bones[spine.utils.indexOf(skeletonData.bones, slotData.boneData)]
|
||||||
local slot = Slot.new(slotData, self, bone)
|
local slot = Slot.new(slotData, self, bone)
|
||||||
table.insert(self.slots, slot)
|
table.insert(self.slots, slot)
|
||||||
|
self.slotsByName[slot.data.name] = slot
|
||||||
table.insert(self.drawOrder, slot)
|
table.insert(self.drawOrder, slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user