diff --git a/README.md b/README.md index f1945108..39ac8265 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ New features: * 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. * 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) * 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. +* Pixi GrayFilter ported over (thanks nickryall #404) Updates: diff --git a/examples/_site/examples.json b/examples/_site/examples.json index 7cec2fe0..26871f0d 100644 --- a/examples/_site/examples.json +++ b/examples/_site/examples.json @@ -252,6 +252,10 @@ "file": "fire.js", "title": "fire" }, + { + "file": "gray.js", + "title": "gray" + }, { "file": "lightbeams.js", "title": "lightbeams" diff --git a/examples/filters/gray.js b/examples/filters/gray.js new file mode 100644 index 00000000..0cf2bafc --- /dev/null +++ b/examples/filters/gray.js @@ -0,0 +1,19 @@ +var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'phaser-example', { preload: preload, create: create }); + +function preload() { + + game.load.image('phaser', 'assets/sprites/phaser2.png'); + game.load.script('gray', '../filters/Gray.js'); + +} + +function create() { + + var logo = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser'); + logo.anchor.setTo(0.5, 0.5); + + var gray = game.add.filter('Gray'); + + logo.filters = [gray]; + +} \ No newline at end of file diff --git a/filters/Gray.js b/filters/Gray.js new file mode 100644 index 00000000..9aafc807 --- /dev/null +++ b/filters/Gray.js @@ -0,0 +1,50 @@ +/** +* @author Mat Groves http://matgroves.com/ @Doormat23 +*/ + +/** +* This turns your displayObjects to grayscale. +* @class Gray +* @contructor +*/ +Phaser.Filter.Gray = function (game) { + + Phaser.Filter.call(this, game); + + this.uniforms.gray = { type: '1f', value: 1.0 }; + + this.fragmentSrc = [ + + "precision mediump float;", + + "varying vec2 vTextureCoord;", + "varying vec4 vColor;", + "uniform sampler2D uSampler;", + "uniform float gray;", + + "void main(void) {", + "gl_FragColor = texture2D(uSampler, vTextureCoord);", + "gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.2126 * gl_FragColor.r + 0.7152 * gl_FragColor.g + 0.0722 * gl_FragColor.b), gray);", + "}" + ]; + +}; + +Phaser.Filter.Gray.prototype = Object.create(Phaser.Filter.prototype); +Phaser.Filter.Gray.prototype.constructor = Phaser.Filter.Gray; + +/** +* The strength of the gray. 1 will make the object black and white, 0 will make the object its normal color +* @property gray +*/ +Object.defineProperty(Phaser.Filter.Gray.prototype, 'gray', { + + get: function() { + return this.uniforms.gray.value; + }, + + set: function(value) { + this.uniforms.gray.value = value; + } + +}); diff --git a/src/time/Time.js b/src/time/Time.js index dbe72023..1d447ac5 100644 --- a/src/time/Time.js +++ b/src/time/Time.js @@ -160,6 +160,7 @@ Phaser.Time.prototype = { */ boot: function () { + this._started = Date.now(); this.events.start(); },