Skip to content

Commit

Permalink
fix: dragonbones skew bug
Browse files Browse the repository at this point in the history
  • Loading branch information
06wj committed Aug 8, 2018
1 parent 43e35d5 commit 9a98581
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions src/extensions/dragonbones/src/hiloFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* HiloSlot
*/
(function(superClass) {
var RAD2DEG = 180/Math.PI;
var RAD2DEG = 180 / Math.PI;
var TextureAtlas = dragonBones.TextureAtlas;
var HiloSlot = function() {
superClass.call(this, this);
Expand Down Expand Up @@ -41,10 +41,9 @@
},
_addDisplayToContainer: function(container, index) {
if (this._display && container) {
if(index){
if (index) {
container.addChildAt(this._display, index);
}
else{
} else {
container.addChild(this._display);
}
}
Expand All @@ -56,11 +55,12 @@
},
_updateTransform: function() {
if (this._display) {
this._display.x = this._global.x;
this._display.y = this._global.y;
this._display.scaleX = this._global.scaleX;
this._display.scaleY = this._global.scaleY;
this._display.rotation = this._global.skewX * RAD2DEG;
var pivotX = this._display.pivotX;
var pivotY = this._display.pivotY;
var mat = this._display.transform;
mat.copy(this._globalTransformMatrix);
mat.tx = mat.tx - mat.a * pivotX - mat.c * pivotY;
mat.ty = mat.ty - mat.b * pivotX - mat.d * pivotY;
}
},
_updateDisplayVisible: function(value) {
Expand Down Expand Up @@ -103,53 +103,50 @@
/**
* HiloFactory
*/
(function(superClass){
(function(superClass) {
var Armature = dragonBones.Armature;
var HiloSlot = dragonBones.HiloSlot;

var HiloFactory = function(){
var HiloFactory = function() {
superClass.call(this, this);
};
__extends(HiloFactory, superClass, {
_generateArmature:function(){
_generateArmature: function() {
var armature = new Armature(new Hilo.Container);
return armature;
},
_generateSlot:function(){
_generateSlot: function() {
var slot = new HiloSlot();
return slot;
},
_generateDisplay:function(textureAtlas, fullName, pivotX, pivotY){
_generateDisplay: function(textureAtlas, fullName, pivotX, pivotY) {
var texture = textureAtlas.getTexture(fullName);
var region = texture.region;
var bitmap = new Hilo.Bitmap({
image:textureAtlas.texture,
rect:[region.x, region.y, region.width, region.height]
image: textureAtlas.texture,
rect: [region.x, region.y, region.width, region.height]
});

if(isNaN(pivotX)||isNaN(pivotY))
{
if (isNaN(pivotX) || isNaN(pivotY)) {
var subTextureFrame = textureAtlas.getFrame(fullName);
if(subTextureFrame != null)
{
pivotX = (subTextureFrame.width/2) + subTextureFrame.x;
pivotY = (subTextureFrame.height/2) + subTextureFrame.y;
}
else
{
pivotX = texture.region.width/2;
pivotY = texture.region.height/2;
if (subTextureFrame != null) {
pivotX = (subTextureFrame.width / 2) + subTextureFrame.x;
pivotY = (subTextureFrame.height / 2) + subTextureFrame.y;
} else {
pivotX = texture.region.width / 2;
pivotY = texture.region.height / 2;
}
}
bitmap.pivotX = pivotX;
bitmap.pivotY = pivotY;
bitmap.transform = new Hilo.Matrix().identity();
return bitmap;
}
});

dragonBones.HiloFactory = HiloFactory;
}(dragonBones.BaseFactory));

dragonBones.tick = function(dt){
dragonBones.tick = function(dt) {
dragonBones.WorldClock.clock.advanceTime(dt * 0.001);
};
};

0 comments on commit 9a98581

Please sign in to comment.