Skip to content

Commit 3568dc4

Browse files
committed
Pixi GrayFilter ported over (thanks nickryall phaserjs#404)
Fixed Time.totalElapsedSeconds, which gets the other filters working again too.
1 parent a8bd5db commit 3568dc4

5 files changed

Lines changed: 75 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ New features:
122122
* Loader.script now has callback (and callbackContext) parameters, so you can specify a function to run once the JS has been injected into the body.
123123
* Phaser.Timer.stop has a new parameter: clearEvents (default true), if true all the events in Timer will be cleared, otherwise they will remain (fixes #383)
124124
* All GameObjects now have a 'destroyChildren' boolean as a parameter to their destroy method. It's default is true and the value propogates down its children.
125+
* Pixi GrayFilter ported over (thanks nickryall #404)
125126

126127

127128
Updates:

examples/_site/examples.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@
252252
"file": "fire.js",
253253
"title": "fire"
254254
},
255+
{
256+
"file": "gray.js",
257+
"title": "gray"
258+
},
255259
{
256260
"file": "lightbeams.js",
257261
"title": "lightbeams"

examples/filters/gray.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'phaser-example', { preload: preload, create: create });
2+
3+
function preload() {
4+
5+
game.load.image('phaser', 'assets/sprites/phaser2.png');
6+
game.load.script('gray', '../filters/Gray.js');
7+
8+
}
9+
10+
function create() {
11+
12+
var logo = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
13+
logo.anchor.setTo(0.5, 0.5);
14+
15+
var gray = game.add.filter('Gray');
16+
17+
logo.filters = [gray];
18+
19+
}

filters/Gray.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @author Mat Groves http://matgroves.com/ @Doormat23
3+
*/
4+
5+
/**
6+
* This turns your displayObjects to grayscale.
7+
* @class Gray
8+
* @contructor
9+
*/
10+
Phaser.Filter.Gray = function (game) {
11+
12+
Phaser.Filter.call(this, game);
13+
14+
this.uniforms.gray = { type: '1f', value: 1.0 };
15+
16+
this.fragmentSrc = [
17+
18+
"precision mediump float;",
19+
20+
"varying vec2 vTextureCoord;",
21+
"varying vec4 vColor;",
22+
"uniform sampler2D uSampler;",
23+
"uniform float gray;",
24+
25+
"void main(void) {",
26+
"gl_FragColor = texture2D(uSampler, vTextureCoord);",
27+
"gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.2126 * gl_FragColor.r + 0.7152 * gl_FragColor.g + 0.0722 * gl_FragColor.b), gray);",
28+
"}"
29+
];
30+
31+
};
32+
33+
Phaser.Filter.Gray.prototype = Object.create(Phaser.Filter.prototype);
34+
Phaser.Filter.Gray.prototype.constructor = Phaser.Filter.Gray;
35+
36+
/**
37+
* The strength of the gray. 1 will make the object black and white, 0 will make the object its normal color
38+
* @property gray
39+
*/
40+
Object.defineProperty(Phaser.Filter.Gray.prototype, 'gray', {
41+
42+
get: function() {
43+
return this.uniforms.gray.value;
44+
},
45+
46+
set: function(value) {
47+
this.uniforms.gray.value = value;
48+
}
49+
50+
});

src/time/Time.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Phaser.Time.prototype = {
160160
*/
161161
boot: function () {
162162

163+
this._started = Date.now();
163164
this.events.start();
164165

165166
},

0 commit comments

Comments
 (0)