-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPixelScaler.js
49 lines (32 loc) · 1.19 KB
/
PixelScaler.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Phaser.Plugin.PixelScaler = function(game, parent) {
Phaser.Plugin.call(this, game, parent);
};
Phaser.Plugin.PixelScaler.prototype = Object.create(Phaser.Plugin.prototype);
Phaser.Plugin.PixelScaler.prototype.init = function(scale) {
this.scale = scale;
this.originalWidth = this.game.width;
this.originalHeight = this.game.height;
this.scaledWidth = this.originalWidth * this.scale;
this.scaledHeight = this.originalHeight * this.scale;
// create a new scaled canvas to draw to
this.scaledCanvas = Phaser.Canvas.create(null, this.scaledWidth, this.scaledHeight, null, true);
this.context = this.scaledCanvas.getContext('2d');
Phaser.Canvas.addToDOM(this.scaledCanvas, this.game.parent);
Phaser.Canvas.setSmoothingEnabled(this.context, false);
this.originalCanvas = this.game.canvas;
this.originalCanvas.style['display'] = 'none';
};
/**
* cop the original canvas to the new canvas
*/
Phaser.Plugin.PixelScaler.prototype.postRender = function() {
this.context.drawImage(
this.originalCanvas,
0, 0,
this.originalWidth,
this.originalHeight,
0, 0,
this.scaledWidth,
this.scaledHeight
);
};