MCPcopy Create free account
hub / github.com/melonjs/melonJS / buildFlipTransform

Function buildFlipTransform

packages/melonjs/tests/tmxlayer-flips.spec.js:13–34  ·  view source on GitHub ↗
(transform, flipMask, width, height)

Source from the content-addressed store, hash-verified

11const FLIP_V_BIT_LOCAL = 2;
12const FLIP_AD_BIT_LOCAL = 4;
13const buildFlipTransform = (transform, flipMask, width, height) => {
14 const halfW = width / 2;
15 const halfH = height / 2;
16 const flippedH = (flipMask & FLIP_H_BIT_LOCAL) !== 0;
17 const flippedV = (flipMask & FLIP_V_BIT_LOCAL) !== 0;
18 const flippedAD = (flipMask & FLIP_AD_BIT_LOCAL) !== 0;
19
20 transform.identity();
21 transform.translate(halfW, halfH);
22 if (flippedAD) {
23 transform.rotate((-90 * Math.PI) / 180);
24 transform.scale(-1, 1);
25 }
26 if (flippedH) {
27 transform.scale(flippedAD ? 1 : -1, flippedAD ? -1 : 1);
28 }
29 if (flippedV) {
30 transform.scale(flippedAD ? -1 : 1, flippedAD ? 1 : -1);
31 }
32 transform.translate(-halfW, -halfH);
33 return transform;
34};
35
36/**
37 * The shader's atlas-sampling code applies the INVERSE of the legacy

Callers 2

Calls 4

identityMethod · 0.45
translateMethod · 0.45
rotateMethod · 0.45
scaleMethod · 0.45

Tested by

no test coverage detected