mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[lua] Ported flipX/flipY -> scaleX/scaleY change. See #1142.
This commit is contained in:
parent
fb67ada3d8
commit
84dcd6ba25
@ -25,7 +25,7 @@ function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
|
|||||||
json.scale = scale
|
json.scale = scale
|
||||||
local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile)
|
local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile)
|
||||||
local skeleton = spine.Skeleton.new(skeletonData)
|
local skeleton = spine.Skeleton.new(skeletonData)
|
||||||
skeleton.flipY = true -- Corona's coordinate system has its y-axis point downwards
|
skeleton.scaleY = -1 -- Corona's coordinate system has its y-axis point downwards
|
||||||
skeleton.group.x = x
|
skeleton.group.x = x
|
||||||
skeleton.group.y = y
|
skeleton.group.y = y
|
||||||
|
|
||||||
|
|||||||
@ -45,8 +45,7 @@ function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y)
|
|||||||
local skeleton = spine.Skeleton.new(skeletonData)
|
local skeleton = spine.Skeleton.new(skeletonData)
|
||||||
skeleton.x = x
|
skeleton.x = x
|
||||||
skeleton.y = y
|
skeleton.y = y
|
||||||
skeleton.flipX = false
|
skeleton.scaleY = -1
|
||||||
skeleton.flipY = true
|
|
||||||
if skin then
|
if skin then
|
||||||
skeleton:setSkin(skin)
|
skeleton:setSkin(skin)
|
||||||
end
|
end
|
||||||
@ -97,13 +96,13 @@ 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("stretchyman-pro", "stretchyman", "sneak", nil, 0.3, 200, 500))
|
||||||
table.insert(skeletons, loadSkeleton("coin-pro", "coin", "rotate", nil, 0.5, 400, 500))
|
table.insert(skeletons, loadSkeleton("coin-pro", "coin", "rotate", nil, 0.5, 400, 500))
|
||||||
table.insert(skeletons, loadSkeleton("spineboy-ess", "spineboy", "walk", nil, 0.5, 400, 500))
|
table.insert(skeletons, loadSkeleton("spineboy-ess", "spineboy", "walk", nil, 0.5, 400, 500))
|
||||||
table.insert(skeletons, loadSkeleton("raptor-pro", "raptor", "walk", nil, 0.3, 400, 500))
|
table.insert(skeletons, loadSkeleton("raptor-pro", "raptor", "walk", nil, 0.3, 400, 500))
|
||||||
table.insert(skeletons, loadSkeleton("goblins-pro", "goblins", "walk", "goblin", 1, 400, 500))
|
table.insert(skeletons, loadSkeleton("goblins-pro", "goblins", "walk", "goblin", 1, 400, 500))
|
||||||
table.insert(skeletons, loadSkeleton("tank-pro", "tank", "drive", nil, 0.2, 600, 500))
|
table.insert(skeletons, loadSkeleton("tank-pro", "tank", "drive", nil, 0.2, 600, 500))
|
||||||
table.insert(skeletons, loadSkeleton("vine-pro", "vine", "grow", nil, 0.3, 400, 500))
|
table.insert(skeletons, loadSkeleton("vine-pro", "vine", "grow", nil, 0.3, 400, 500))
|
||||||
table.insert(skeletons, loadSkeleton("stretchyman-pro", "stretchyman", "sneak", nil, 0.3, 200, 500))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update (delta)
|
function love.update (delta)
|
||||||
|
|||||||
@ -377,7 +377,7 @@ function AnimationState:apply (skeleton)
|
|||||||
for i,current in pairs(tracks) do
|
for i,current in pairs(tracks) do
|
||||||
if not (current == nil or current.delay > 0) then
|
if not (current == nil or current.delay > 0) then
|
||||||
applied = true
|
applied = true
|
||||||
<<<<<<< HEAD
|
|
||||||
local blend = current.mixBlend
|
local blend = current.mixBlend
|
||||||
if i == 0 then blend = MixBlend.first end
|
if i == 0 then blend = MixBlend.first end
|
||||||
|
|
||||||
@ -385,15 +385,6 @@ function AnimationState:apply (skeleton)
|
|||||||
local mix = current.alpha
|
local mix = current.alpha
|
||||||
if current.mixingFrom then
|
if current.mixingFrom then
|
||||||
mix = mix * self:applyMixingFrom(current, skeleton, blend)
|
mix = mix * self:applyMixingFrom(current, skeleton, blend)
|
||||||
=======
|
|
||||||
local currrentPose = MixPose.currentLayered
|
|
||||||
if i == 0 then currentPose = MixPose.current end
|
|
||||||
|
|
||||||
-- Apply mixing from entries first.
|
|
||||||
local mix = current.alpha
|
|
||||||
if current.mixingFrom then
|
|
||||||
mix = mix * self:applyMixingFrom(current, skeleton, currentPose)
|
|
||||||
>>>>>>> 3.6
|
|
||||||
elseif current.trackTime >= current.trackEnd and current.next == nil then
|
elseif current.trackTime >= current.trackEnd and current.next == nil then
|
||||||
mix = 0
|
mix = 0
|
||||||
end
|
end
|
||||||
@ -411,19 +402,13 @@ function AnimationState:apply (skeleton)
|
|||||||
local firstFrame = #current.timelinesRotation == 0
|
local firstFrame = #current.timelinesRotation == 0
|
||||||
local timelinesRotation = current.timelinesRotation
|
local timelinesRotation = current.timelinesRotation
|
||||||
|
|
||||||
for i,timeline in ipairs(timelines) do
|
for ii,timeline in ipairs(timelines) do
|
||||||
<<<<<<< HEAD
|
|
||||||
local timelineBlend = MixBlend.setup
|
local timelineBlend = MixBlend.setup
|
||||||
if timelineData[i] == SUBSEQUENT then timelineBlend = blend end
|
if timelineData[ii] == SUBSEQUENT then timelineBlend = blend end
|
||||||
|
|
||||||
=======
|
|
||||||
local pose = MixPose.currentPose
|
|
||||||
if timelineData[i] >= FIRST then pose = MixPose.setup end
|
|
||||||
|
|
||||||
>>>>>>> 3.6
|
|
||||||
if timeline.type == Animation.TimelineType.rotate then
|
if timeline.type == Animation.TimelineType.rotate then
|
||||||
self:applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, i * 2,
|
self:applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii * 2,
|
||||||
firstFrame) -- FIXME passing ii * 2, indexing correct?
|
firstFrame)
|
||||||
else
|
else
|
||||||
timeline:apply(skeleton, animationLast, animationTime, events, mix, timelineBlend, MixDirection._in)
|
timeline:apply(skeleton, animationLast, animationTime, events, mix, timelineBlend, MixDirection._in)
|
||||||
end
|
end
|
||||||
@ -468,7 +453,6 @@ function AnimationState:applyMixingFrom (to, skeleton, blend)
|
|||||||
for i,timeline in ipairs(timelines) do
|
for i,timeline in ipairs(timelines) do
|
||||||
timeline:apply(skeleton, animationLast, animationTime, events, alphaMix, blend, MixDirection.out)
|
timeline:apply(skeleton, animationLast, animationTime, events, alphaMix, blend, MixDirection.out)
|
||||||
end
|
end
|
||||||
<<<<<<< HEAD
|
|
||||||
else
|
else
|
||||||
local timelineData = from.timelineData
|
local timelineData = from.timelineData
|
||||||
local timelineDipMix = from.timelineDipMix
|
local timelineDipMix = from.timelineDipMix
|
||||||
@ -493,13 +477,6 @@ function AnimationState:applyMixingFrom (to, skeleton, blend)
|
|||||||
elseif timelineData[i] == DIP then
|
elseif timelineData[i] == DIP then
|
||||||
timelineBlend = MixBlend.setup
|
timelineBlend = MixBlend.setup
|
||||||
alpha = alphaDip
|
alpha = alphaDip
|
||||||
=======
|
|
||||||
|
|
||||||
if not skipSubsequent then
|
|
||||||
from.totalAlpha = from.totalAlpha + alpha
|
|
||||||
if timeline.type == Animation.TimelineType.rotate then
|
|
||||||
self:applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i * 2, firstFrame)
|
|
||||||
>>>>>>> 3.6
|
|
||||||
else
|
else
|
||||||
timelineBlend = MixBlend.setup
|
timelineBlend = MixBlend.setup
|
||||||
local dipMix = timelineDipMix[i]
|
local dipMix = timelineDipMix[i]
|
||||||
@ -525,13 +502,8 @@ function AnimationState:applyMixingFrom (to, skeleton, blend)
|
|||||||
return mix
|
return mix
|
||||||
end
|
end
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, blend, timelinesRotation, i, firstFrame)
|
function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, blend, timelinesRotation, i, firstFrame)
|
||||||
if firstFrame then
|
if firstFrame then
|
||||||
=======
|
|
||||||
function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame)
|
|
||||||
if firstFrame then
|
|
||||||
>>>>>>> 3.6
|
|
||||||
timelinesRotation[i] = 0
|
timelinesRotation[i] = 0
|
||||||
timelinesRotation[i+1] = 0
|
timelinesRotation[i+1] = 0
|
||||||
end
|
end
|
||||||
@ -858,13 +830,8 @@ function AnimationState:_animationsChanged ()
|
|||||||
local mixingTo = self.mixingTo
|
local mixingTo = self.mixingTo
|
||||||
|
|
||||||
for i, entry in pairs(self.tracks) do
|
for i, entry in pairs(self.tracks) do
|
||||||
<<<<<<< HEAD
|
|
||||||
if entry and (i == 0 or entry.mixBlend ~= MixBlend.add) then
|
if entry and (i == 0 or entry.mixBlend ~= MixBlend.add) then
|
||||||
entry:setTimelineData(nil, mixingTo, propertyIDs)
|
entry:setTimelineData(nil, mixingTo, propertyIDs)
|
||||||
=======
|
|
||||||
if entry then
|
|
||||||
entry:setTimelineData(nil, mixingTo, propertyIDs)
|
|
||||||
>>>>>>> 3.6
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -96,32 +96,21 @@ function Bone:updateWorldTransformWith (x, y, rotation, scaleX, scaleY, shearX,
|
|||||||
self.ashearY = shearY
|
self.ashearY = shearY
|
||||||
self.appliedValid = true
|
self.appliedValid = true
|
||||||
|
|
||||||
|
local sx = self.skeleton.scaleX;
|
||||||
|
local sy = self.skeleton.scaleY;
|
||||||
|
|
||||||
local parent = self.parent
|
local parent = self.parent
|
||||||
if parent == nil then
|
if parent == nil then
|
||||||
local rotationY = rotation + 90 + shearY
|
local rotationY = rotation + 90 + shearY
|
||||||
local rotationRad = math_rad(rotation + shearX)
|
local rotationRad = math_rad(rotation + shearX)
|
||||||
local rotationYRad = math_rad(rotationY)
|
local rotationYRad = math_rad(rotationY)
|
||||||
local la = math_cos(rotationRad) * scaleX
|
|
||||||
local lb = math_cos(rotationYRad) * scaleY
|
|
||||||
local lc = math_sin(rotationRad) * scaleX
|
|
||||||
local ld = math_sin(rotationYRad) * scaleY
|
|
||||||
local skeleton = self.skeleton
|
local skeleton = self.skeleton
|
||||||
if skeleton.flipX then
|
self.a = math_cos(rotationRad) * scaleX * sx
|
||||||
x = -x
|
self.b = math_cos(rotationYRad) * scaleY * sy
|
||||||
la = -la
|
self.c = math_sin(rotationRad) * scaleX * sx
|
||||||
lb = -lb
|
self.d = math_sin(rotationYRad) * scaleY * sy
|
||||||
end
|
self.worldX = x * sx + skeleton.x
|
||||||
if skeleton.flipY then
|
self.worldY = y * sy + skeleton.y
|
||||||
y = -y
|
|
||||||
lc = -lc
|
|
||||||
ld = -ld
|
|
||||||
end
|
|
||||||
self.a = la
|
|
||||||
self.b = lb
|
|
||||||
self.c = lc
|
|
||||||
self.d = ld
|
|
||||||
self.worldX = x + skeleton.x
|
|
||||||
self.worldY = y + skeleton.y
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -176,8 +165,8 @@ function Bone:updateWorldTransformWith (x, y, rotation, scaleX, scaleY, shearX,
|
|||||||
elseif transformMode == TransformMode.noScale or transformMode == TransformMode.noScaleOrReflection then
|
elseif transformMode == TransformMode.noScale or transformMode == TransformMode.noScaleOrReflection then
|
||||||
local cos = math_cos(math_rad(rotation))
|
local cos = math_cos(math_rad(rotation))
|
||||||
local sin = math_sin(math_rad(rotation))
|
local sin = math_sin(math_rad(rotation))
|
||||||
local za = pa * cos + pb * sin
|
local za = (pa * cos + pb * sin) / sx
|
||||||
local zc = pc * cos + pd * sin
|
local zc = (pc * cos + pd * sin) / sy
|
||||||
local s = math_sqrt(za * za + zc * zc)
|
local s = math_sqrt(za * za + zc * zc)
|
||||||
if s > 0.00001 then s = 1 / s end
|
if s > 0.00001 then s = 1 / s end
|
||||||
za = za * s
|
za = za * s
|
||||||
@ -190,27 +179,16 @@ function Bone:updateWorldTransformWith (x, y, rotation, scaleX, scaleY, shearX,
|
|||||||
local lb = math_cos(math_rad(90 + shearY)) * scaleY;
|
local lb = math_cos(math_rad(90 + shearY)) * scaleY;
|
||||||
local lc = math_sin(math_rad(shearX)) * scaleX;
|
local lc = math_sin(math_rad(shearX)) * scaleX;
|
||||||
local ld = math_sin(math_rad(90 + shearY)) * scaleY;
|
local ld = math_sin(math_rad(90 + shearY)) * scaleY;
|
||||||
local flip = self.skeleton.flipX ~= self.skeleton.flipY
|
|
||||||
if transformMode ~= TransformMode.noScaleOrReflection then flip = pa * pd - pb * pc < 0 end
|
|
||||||
if flip then
|
|
||||||
zb = -zb
|
|
||||||
zd = -zd
|
|
||||||
end
|
|
||||||
self.a = za * la + zb * lc
|
self.a = za * la + zb * lc
|
||||||
self.b = za * lb + zb * ld
|
self.b = za * lb + zb * ld
|
||||||
self.c = zc * la + zd * lc
|
self.c = zc * la + zd * lc
|
||||||
self.d = zc * lb + zd * ld
|
self.d = zc * lb + zd * ld
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.skeleton.flipX then
|
self.a = self.a * sx
|
||||||
self.a = -self.a
|
self.b = self.b * sx
|
||||||
self.b = -self.b
|
self.c = self.c * sy
|
||||||
end
|
self.d = self.d * sy
|
||||||
if self.skeleton.flipY then
|
|
||||||
self.c = -self.c
|
|
||||||
self.d = -self.d
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Bone:setToSetupPose ()
|
function Bone:setToSetupPose ()
|
||||||
|
|||||||
@ -63,7 +63,7 @@ function Skeleton.new (data)
|
|||||||
skin = nil,
|
skin = nil,
|
||||||
color = Color.newWith(1, 1, 1, 1),
|
color = Color.newWith(1, 1, 1, 1),
|
||||||
time = 0,
|
time = 0,
|
||||||
flipX = false, flipY = false,
|
scaleX = 1, scaleY = 1,
|
||||||
x = 0, y = 0
|
x = 0, y = 0
|
||||||
}
|
}
|
||||||
setmetatable(self, Skeleton)
|
setmetatable(self, Skeleton)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user