Skip to content

Commit

Permalink
Modify spine file loader, support slot and display object scale.
Browse files Browse the repository at this point in the history
  • Loading branch information
watsonsong committed Sep 27, 2013
1 parent 7e55ed4 commit 94a3499
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions src/utils/formatSpineData.as
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const TRANSLATE:String = "translate";
const SCALE:String = "scale";
const COMBINE:String = "combine";
const ATTACHMENT:String = "attachment";
const ADDITIVE:String = "additive";
const COLOR:String = "color";
const A_NAME:String = "name";
Expand Down Expand Up @@ -142,16 +143,16 @@ function formatBone(boneObject:Object):XML
case "1":
case "true":
case "yes":
boneXML.@[ConstValues.A_SCALE_MODE] = 0;
boneXML.@[ConstValues.A_SCALE_MODE] = 2;
break;
default:
boneXML.@[ConstValues.A_SCALE_MODE] = 1;
boneXML.@[ConstValues.A_SCALE_MODE] = 0;
break;
}
}
else
{
boneXML.@[ConstValues.A_SCALE_MODE] = 0;
boneXML.@[ConstValues.A_SCALE_MODE] = 2;
}

var parent:String = boneObject[A_PARENT];
Expand All @@ -172,6 +173,7 @@ function formatSkin(skinObject:Object, skinName:String, slotList:Array, textureA
var parentName:String;
var firstAttachment:String;
var blendMode:String;
var zOrder:int;
for(var slotName:String in skinObject)
{
Expand All @@ -183,24 +185,42 @@ function formatSkin(skinObject:Object, skinName:String, slotList:Array, textureA
{
parentName = slotObjectInList[A_BONE];
firstAttachment = slotObjectInList[ATTACHMENT];
var additive:Object = slotObjectInList[ADDITIVE];
if(additive && additive is Boolean)
{
var isAdditive:Boolean = additive as Boolean;
if(isAdditive)
{
blendMode = "add";
}
else
{
blendMode = "normal";
}
}
else
{
blendMode = "normal";
}
break;
}
zOrder ++;
}
//默认的display标记出来,以便放到displayList的首位
skinXML.appendChild(formatSlot(skinObject[slotName], slotName, parentName, firstAttachment, zOrder, textureAtlasXML));
skinXML.appendChild(formatSlot(skinObject[slotName], slotName, parentName, firstAttachment, blendMode, zOrder, textureAtlasXML));
}

return skinXML;
}

function formatSlot(slotObject:Object, slotName:String, slotParent:String, firstAttachment:String, zOrder:int, textureAtlasXML:XML):XML
function formatSlot(slotObject:Object, slotName:String, slotParent:String, firstAttachment:String, blendMode:String, zOrder:int, textureAtlasXML:XML):XML
{
var slotXML:XML =
<{ConstValues.SLOT}
{ConstValues.A_NAME}={slotName}
{ConstValues.A_PARENT}={slotParent}
{ConstValues.A_Z_ORDER}={zOrder}
{ConstValues.A_BLENDMODE}={blendMode}
/>;
var displayXML:XML;
Expand Down Expand Up @@ -240,6 +260,17 @@ function formatDisplay(displayObject:Object, displayName:String, textureAtlasXML
scaleX = width / Number(subTextureXML.@[ConstValues.A_WIDTH]);
scaleY = height / Number(subTextureXML.@[ConstValues.A_HEIGHT]);

var spineScaleX:String = displayObject[A_SCALE_X];
if (spineScaleX)
{
scaleX *= Number(spineScaleX);
}
var spineScaleY:String = displayObject[A_SCALE_Y];
if (spineScaleY)
{
scaleY *= Number(spineScaleY);
}

if(isNaN(scaleX))
{
scaleX = 1;
Expand Down

0 comments on commit 94a3499

Please sign in to comment.