瀏覽代碼

Merge pull request #54 from moitias/master

Fix scaling when attachment is rotated 90 degrees from the bone, Add relative paths to package.path when running in simulator to make the example work straight out of the box
Nathan Sweet 12 年之前
父節點
當前提交
a26bdd34e4
共有 1 個文件被更改,包括 16 次插入2 次删除
  1. 16 2
      spine-corona/spine-corona/spine.lua

+ 16 - 2
spine-corona/spine-corona/spine.lua

@@ -25,6 +25,10 @@
 
 spine = {}
 
+if (system.getInfo("environment") == "simulator") then
+	package.path = package.path .. ";".. system.pathForFile("../") .. "/?.lua"
+end
+
 spine.utils = require "spine-lua.utils"
 spine.SkeletonJson = require "spine-lua.SkeletonJson"
 spine.SkeletonData = require "spine-lua.SkeletonData"
@@ -108,8 +112,18 @@ function spine.Skeleton.new (skeletonData, group)
 					image.x = slot.bone.worldX + attachment.x * slot.bone.m00 + attachment.y * slot.bone.m01
 					image.y = -(slot.bone.worldY + attachment.x * slot.bone.m10 + attachment.y * slot.bone.m11)
 					image.rotation = -(slot.bone.worldRotation + attachment.rotation)
-					image.xScale = slot.bone.worldScaleX + attachment.scaleX - 1
-					image.yScale = slot.bone.worldScaleY + attachment.scaleY - 1
+
+					-- fix scaling when attachment is rotated 90 degrees
+					local rot = math.abs(attachment.rotation) % 180
+					if (rot == 90) then
+					    image.xScale = slot.bone.worldScaleY * attachment.scaleX
+					    image.yScale = slot.bone.worldScaleX * attachment.scaleY
+					else
+					    --if (rot ~= 0 and (slot.bone.worldScaleX ~= 1 or slot.bone.worldScaleY ~= 1)) then print("WARNING: Scaling bones with attachments not rotated to the cardinal angles will not work as expected in Corona!") end
+					    image.xScale = slot.bone.worldScaleX * attachment.scaleX
+					    image.yScale = slot.bone.worldScaleY * attachment.scaleY
+					end
+
 					if self.flipX then
 						image.xScale = -image.xScale
 						image.rotation = -image.rotation