Skip to content

Commit

Permalink
Fix #20 particles now displaying, misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLaumeister committed Dec 24, 2019
1 parent d134b73 commit a2b0c14
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/GridRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GridRenderer { // eslint-disable-line no-unused-vars
Util.assert(arguments.length === 3);

const playheadX = grid.player.getPlayheadX();
const dpr = Util.getDevicePixelRatio();

// Defaults
this.ctx.globalAlpha = 1;
Expand Down Expand Up @@ -75,7 +76,7 @@ class GridRenderer { // eslint-disable-line no-unused-vars
// Create particles
const px = dx * (gridx + 0.5);
const py = dy * (gridy + 0.5);
const velocityscalar = 10 * this.DPR;
const velocityscalar = 10 * dpr;
const numparticles = 20;
for (let j = 0; j < 2 * Math.PI; j += (2 * Math.PI) / numparticles) {
const pvx = Math.cos(j) * velocityscalar;
Expand Down
2 changes: 1 addition & 1 deletion src/SpriteSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SpriteSheet { // eslint-disable-line no-unused-vars
this.spriteSheet.width = 3 * this.tileWidth; // 3 sprites. very magical
this.spriteSheet.height = this.tileHeight;

const currentDevicePixelRatio = devicePixelRatio || 1;
const currentDevicePixelRatio = Util.getDevicePixelRatio();

// For all rectangles

Expand Down
4 changes: 4 additions & 0 deletions src/ToneMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class ToneMatrix { // eslint-disable-line no-unused-vars
},
);
});
this.c.addEventListener('touchend', (e) => {
e.preventDefault(); // Prevent emulated click
this.resetCanvasMousePosition();
});
this.c.addEventListener('touchmove', (e) => {
e.preventDefault(); // Prevent emulated click
Array.from(e.touches).forEach(
Expand Down
19 changes: 19 additions & 0 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ class Util { // eslint-disable-line no-unused-vars
}
}

/**
* Gets the current devicePixelRatio in a performant way
* @returns {number} - The device pixel ratio
*/
static getDevicePixelRatio() {
return Util.devicePixelRatio;
}

/**
* Logs an error to the console if an assertion is false
* @param {boolean} bool - The assertion to check
Expand All @@ -84,3 +92,14 @@ class Util { // eslint-disable-line no-unused-vars
if (!bool) console.error('assertion failed');
}
}

Util.devicePixelRatio = 1;

(function initPixelRatio() {
const mqString = `(resolution: ${window.devicePixelRatio}dppx)`;
const updatePixelRatio = () => {
Util.devicePixelRatio = window.devicePixelRatio || 1;
};
updatePixelRatio();
matchMedia(mqString).addEventListener('change', updatePixelRatio);
}());

0 comments on commit a2b0c14

Please sign in to comment.