Skip to content

Commit

Permalink
Merge pull request #80 from whl88/master
Browse files Browse the repository at this point in the history
设置中心点支持分别设置XY方向位置
  • Loading branch information
drawcall authored Aug 23, 2021
2 parents ec7731b + 33e7ae5 commit fb467d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/node/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class FFImage extends FFNode {
await this.isReady();

const [width, height] = this.getWH();
const offsetX = width * this.anchor;
const offsetY = height * this.anchor;
const offsetX = width * this.anchor[0];
const offsetY = height * this.anchor[1];
this.setOffset(offsetX, offsetY);
}

Expand Down
14 changes: 9 additions & 5 deletions lib/node/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FFNode extends FFBase {
this.offsetX = 0;
this.offsetY = 0;
this.duration = 0;
this.anchor = 0.5;
this.anchor = [0.5,0.5];
this.parent = null;

this.createDisplay();
Expand All @@ -58,12 +58,15 @@ class FFNode extends FFBase {

/**
* Set display object registration center
* @param {number} anchor
* @param {number|Array} anchor eg. [1,0.5] anchor[0] is X ,anchor[1] is Y. If you pass a number 1, it means [1,1]
* @public
*/
setAnchor(anchor) {
if(typeof anchor === 'number'){
anchor = [anchor,anchor]
}
this.anchor = anchor;
this.display.attr({ anchor: [anchor, anchor] });
this.display.attr({ anchor: [anchor[0], anchor[1]] });
}

/**
Expand Down Expand Up @@ -95,8 +98,9 @@ class FFNode extends FFBase {
}

/**
* Set the duration of node in the scene
* @param {number} duration
* Set the offset of node in the scene
* @param {number} offsetX
* @param {number} offsetY
* @public
*/
setOffset(offsetX, offsetY) {
Expand Down

0 comments on commit fb467d4

Please sign in to comment.