forked from VanceCole/macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
position.js
27 lines (26 loc) · 935 Bytes
/
position.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Get canvas position given PIXI Container like object
*/
function getCanvasPos(context) {
const { x, y } = context.toGlobal(new PIXI.Point());
const t = canvas.stage.worldTransform;
let nx = (x - t.tx) / canvas.stage.scale.x;
let ny = (y - t.ty) / canvas.stage.scale.y;
return { x: nx, y: ny};
}
/**
* Converts the coordinates of a Point from one context to another
*
* @param {PIXI.IPointData} point - The Point to convert
* @param {PIXI.Container} context1 - The context the point is currently in
* @param {PIXI.Container} context2 - The context to translate the point to
* @return {PIXI.Point} A Point representing the coordinates in the second context
*/
function translatePoint(point, context1, context2) {
const pt = new PIXI.Container();
context1.addChild(pt);
pt.position.set(point.x, point.y);
const tp = context2.toLocal(new PIXI.Point(), pt);
context1.removeChild(pt);
return tp;
}