From 7c7e924b7ad16245b079fed7081ec2a6ffacf463 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Tue, 1 Jul 2014 16:26:23 +0100 Subject: [PATCH] Fixed Pixelate to pass jshint and be more in line with Phaser Filters. --- filters/Pixelate.js | 68 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/filters/Pixelate.js b/filters/Pixelate.js index 7996c9328..119602b7c 100644 --- a/filters/Pixelate.js +++ b/filters/Pixelate.js @@ -1,65 +1,65 @@ /** - * Original author of PixelateFilter: Mat Groves http://matgroves.com/ @Doormat23 - * adapted for Phaser.js - */ +* Original author of PixelateFilter: Mat Groves http://matgroves.com/ @Doormat23 +* adapted for Phaser.js +*/ /** - * - * This filter applies a pixelate effect making display objects appear 'blocky' - * @class PixelateFilter - * @contructor - */ -Phaser.Filter.Pixelate = function() -{ +* This filter applies a pixelate effect making display objects appear 'blocky' +* @class PixelateFilter +* @contructor +*/ +Phaser.Filter.Pixelate = function(game) { + Phaser.Filter.call(this, game); this.passes = [this]; - // set the uniforms - this.uniforms = { - invert: {type: '1f', value: 0}, - dimensions: {type: '4fv', value:new Float32Array([10000, 100, 10, 10])}, - pixelSize: {type: '2f', value:{x:10, y:10}}, - }; + this.uniforms.invert = { type: '1f', value: 0 }; + this.uniforms.pixelSize = { type: '2f', value: { x: 10, y: 10 } }; + this.uniforms.dimensions = { type: '4fv', value: new Float32Array( [ 10000, 100, 10, 10 ] ) }; this.fragmentSrc = [ - 'precision mediump float;', - 'varying vec2 vTextureCoord;', - 'varying vec4 vColor;', - 'uniform vec2 testDim;', - 'uniform vec4 dimensions;', - 'uniform vec2 pixelSize;', - 'uniform sampler2D uSampler;', - 'void main(void) {', - ' vec2 coord = vTextureCoord;', + "precision mediump float;", + "varying vec2 vTextureCoord;", + "varying vec4 vColor;", + "uniform vec2 testDim;", + "uniform vec4 dimensions;", + "uniform vec2 pixelSize;", + "uniform sampler2D uSampler;", - ' vec2 size = dimensions.xy/pixelSize;', + "void main(void)", + "{", - ' vec2 color = floor( ( vTextureCoord * size ) ) / size + pixelSize/dimensions.xy * 0.5;', - ' gl_FragColor = texture2D(uSampler, color);', - '}' + "vec2 coord = vTextureCoord;", + "vec2 size = dimensions.xy/pixelSize;", + "vec2 color = floor( ( vTextureCoord * size ) ) / size + pixelSize/dimensions.xy * 0.5;", + "gl_FragColor = texture2D(uSampler, color);", + "}" ]; }; - Phaser.Filter.Pixelate.prototype = Object.create(Phaser.Filter.prototype); Phaser.Filter.Pixelate.prototype.constructor = Phaser.Filter.Pixelate; - /** - * * This a point that describes the size of the blocs. x is the width of the block and y is the the height * @property size * @type Point */ Object.defineProperty(Phaser.Filter.prototype, 'size', { + get: function() { + return this.uniforms.pixelSize.value; + }, + set: function(value) { + this.dirty = true; this.uniforms.pixelSize.value = value; - } -}); + } + +});