MCPcopy Create free account
hub / github.com/SpringRoll/SpringRoll / Anchor

Class Anchor

src/scale-manager/Anchor.js:20–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 * @implements ScaledEntity
19 */
20export class Anchor extends ScaledEntity {
21 /**
22 * Creates an instance of Anchor.
23 * @param {object} param
24 * @param {Point} param.position
25 * @param {Point} [param.direction= {x: -1, y: -1}]
26 * @param {PositionCallback} param.callback
27 * @memberof Anchor
28 */
29 constructor({
30 position,
31 direction,
32 callback = () => Debugger.log('warn', this, 'Anchor missing callback')
33 } = {}) {
34 super();
35 this.position = position || { x: 0, y: 0 };
36 this.direction = direction || { x: -1, y: -1 };
37 this.callback = callback;
38 }
39
40 /**
41 * @param {object} param
42 * @param {Point} param.viewArea
43 * @return {void} @memberof Anchor
44 */
45 onResize({ viewArea }) {
46 const halfWidth = viewArea.width * 0.5;
47 const halfHeight = viewArea.height * 0.5;
48
49 const centerX = viewArea.x + halfWidth;
50 const centerY = viewArea.y + halfHeight;
51
52 const x = centerX + (this.direction.x * halfWidth) + this.position.x;
53 const y = centerY + (this.direction.y * halfHeight) + this.position.y;
54
55 this.callback({ x, y });
56 }
57}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected