Skip to content

Commit

Permalink
Fix #1: high DPI display blur
Browse files Browse the repository at this point in the history
Use window.devicePixelRatio
  • Loading branch information
ganlvtech committed Feb 9, 2019
1 parent 1cde584 commit b23378e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ export default class CatchTheCatGame extends Phaser.Game {
public readonly mainScene: MainScene;

constructor(w: number, h: number, r: number, parent?: HTMLElement | string) {
r = r * window.devicePixelRatio;
let scene = new MainScene(w, h, r);
const config: GameConfig = {
width: Math.floor((6.5 + 2 * w) * r),
height: Math.floor((6.5 + Math.sqrt(3) * h) * r),
height: Math.floor((6 + Math.sqrt(3) * h) * r),
type: Phaser.AUTO,
parent: parent,
backgroundColor: 0xeeeeee,
scene: scene,
zoom: 1 / window.devicePixelRatio,
};
super(config);
this.mainScene = scene;
Expand Down
7 changes: 4 additions & 3 deletions src/sprites/resetButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import _ from "../i18n";
export default class ResetButton extends Phaser.GameObjects.Text {
constructor(scene: MainScene) {
super(scene, 0, 0, _("重置"), {});
this.setFontSize(20);
this.setColor("#000000");
this.setPadding(16, 16, 16, 16);
let y = (4 + Math.sqrt(3) * scene.h) * scene.r;
let r = scene.r;
this.setFontSize(r);
this.setPadding(r, r, r, r);
let y = (3 + Math.sqrt(3) * scene.h) * scene.r;
this.setPosition(0, y);
let shape = new Phaser.Geom.Rectangle(0, 0, this.width, this.height);
this.setInteractive(shape, Phaser.Geom.Rectangle.Contains);
Expand Down
10 changes: 5 additions & 5 deletions src/sprites/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import MainScene from "../scenes/mainScene";

export default class StatusBar extends Phaser.GameObjects.Text {
constructor(scene: MainScene) {
super(scene, 0, 0, "", {
fontSize: "20px",
fill: "#000000",
});
this.setPadding(16, 16, 16, 16);
super(scene, 0, 0, "", {});
this.setColor("#000000");
let r = scene.r;
this.setFontSize(r);
this.setPadding(r, r, r, r);
}
}

0 comments on commit b23378e

Please sign in to comment.