Skip to content

Commit

Permalink
pivot and anchor fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Dec 13, 2021
1 parent 9713e36 commit b948a39
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Binary file removed example/assets/sprites/ref.png
Binary file not shown.
24 changes: 12 additions & 12 deletions example/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const game = new Phaser.Game({
renderer: Phaser.CANVAS,
parent: 'game',
scaleMode: Phaser.ScaleManager.USER_SCALE,
state: { preload, create, update },
state: { preload, create },
backgroundColor: '#333',
});

Expand All @@ -28,9 +28,7 @@ let _colorIndex = 0;
// ======================================================== //

function preload() {
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.image('phaser', 'assets/sprites/phaser1.png');
game.load.image('ref', 'assets/sprites/ref.png');
game.load.bitmapFont('font', 'assets/fonts/nokia.png', 'assets/fonts/nokia.xml');
}

Expand Down Expand Up @@ -114,22 +112,24 @@ function create() {
child = el(DIST * 3, 500, SIZE, SIZE, parent, 'child-inverted');
child.scale.set(-1, -1);

child = game.add.sprite(900, 600, 'phaser');
child.name = 'sprite';
child.scale.set(2, 2);
child.inputEnabled = true;

game.add.bitmapText(50, 50, 'font', 'This is a bitmap text', 30)
.name = 'bitmap text';

child = el(900, 700, SIZE * 4, SIZE * 4, parent, 'deep-hierarchy');
child = el(960, -100, SIZE * 4, SIZE * 4, parent, 'deep-hierarchy');
child = el(50, 50, SIZE * 3.5, SIZE * 3.5, child, 'child-1');
child = el(50, 50, SIZE * 3, SIZE * 3, child, 'child-2');
child = el(50, 50, SIZE * 2.5, SIZE * 2.5, child, 'child-3');
child = el(50, 50, SIZE * 2, SIZE * 2, child, 'child-4');
child = el(50, 50, SIZE * 1.5, SIZE * 1.5, child, 'child-5');
child = el(50, 50, SIZE, SIZE, child, 'child-6');

const bt = game.add.bitmapText(50, 50, 'font', 'This is a bitmap text', 30);
bt.name = 'bitmap text';

const sprite = game.add.sprite(960, 540, 'phaser');
sprite.name = 'sprite';
sprite.scale.set(2, 2);
sprite.anchor.set(0.5, 0.5);
sprite.inputEnabled = true;
sprite.pivot.set(0, 20);

plugin.show();
}

Expand Down
4 changes: 2 additions & 2 deletions src/scene-view/selection-area/gizmos/selection-gizmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export class SelectionGizmo extends HTMLElement implements Gizmo {

if (object.anchor) {
SelectionUtil.pointFromGameToArea(
object.anchor.x * (object.width / object.scale.x),
object.anchor.y * (object.height / object.scale.y),
object.anchor.x * bounds.width,
object.anchor.y * bounds.height,
_pointCache1
);
this.anchor.style.top = _pointCache1.y + 'px';
Expand Down
7 changes: 7 additions & 0 deletions src/scene-view/selection-area/handlers/scale.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export class ScaleHandler implements DraggingHandler {
y: (object.pivot.y / (object.height / object.scale.y)),
};

if (object.anchor && 'texture' in object) {
this._normalizedPivot = {
x: object.anchor.x + this._normalizedPivot.x,
y: object.anchor.y + this._normalizedPivot.y,
};
}

this._vsign = Math.sign(vside - 0.5);
this._hsign = Math.sign(hside - 0.5);

Expand Down

0 comments on commit b948a39

Please sign in to comment.