Phaser.BitmapData = function (game, width, height){ if (typeof width === 'undefined') { width = 256; } if (typeof height === 'undefined') { height = 256; } this.game = game; this.name = ''; this.width = width; this.height = height; this.canvas = Phaser.Canvas.create(width, height); this.context = this.canvas.getContext('2d'); this.imageData = this.context.getImageData(0, 0, width, height); if (this.imageData.data.buffer) { this.pixels = this.imageData.data.buffer; } else { this.pixels = this.imageData.data; } this.baseTexture = new PIXI.BaseTexture(this.canvas); this.texture = new PIXI.Texture(this.baseTexture); this.textureFrame = new Phaser.Frame(0, 0, 0, width, height, 'bitmapData', game.rnd.uuid()); this.type = Phaser.BITMAPDATA; this._dirty = false ; } ; Phaser.BitmapData.prototype = { add: function (sprite){ sprite.loadTexture(this); } , addTo: function (sprites){ for (var i = 0; i < _AN_Read_length('length', sprites); i++ ){ if (sprites[i].texture) { sprites[i].loadTexture(this); } } } , clear: function (){ this.context.clearRect(0, 0, this.width, this.height); this._dirty = true ; } , refreshBuffer: function (){ this.imageData = this.context.getImageData(0, 0, this.width, this.height); this.pixels = new Int32Array(this.imageData.data.buffer); } , setPixel32: function (x, y, red, green, blue, alpha){ if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) { this.pixels[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red; this.context.putImageData(this.imageData, 0, 0); this._dirty = true ; } } , setPixel: function (x, y, red, green, blue){ this.setPixel32(x, y, red, green, blue, 255); } , getPixel: function (x, y){ if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) { return this.data32[y * this.width + x]; } } , getPixel32: function (x, y){ if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) { return this.data32[y * this.width + x]; } } , getPixels: function (rect){ return this.context.getImageData(rect.x, rect.y, rect.width, rect.height); } , arc: function (x, y, radius, startAngle, endAngle, anticlockwise){ if (typeof anticlockwise === 'undefined') { anticlockwise = false ; } this._dirty = true ; this.context.arc(x, y, radius, startAngle, endAngle, anticlockwise); return this; } , arcTo: function (x1, y1, x2, y2, radius){ this._dirty = true ; this.context.arcTo(x1, y1, x2, y2, radius); return this; } , beginFill: function (color){ this.fillStyle(color); return this; } , beginLinearGradientFill: function (colors, ratios, x0, y0, x1, y1){ var gradient = this.createLinearGradient(x0, y0, x1, y1); for (var i = 0, len = _AN_Read_length('length', colors); i < len; i++ ){ gradient.addColorStop(ratios[i], colors[i]); } this.fillStyle(gradient); return this; } , beginLinearGradientStroke: function (colors, ratios, x0, y0, x1, y1){ var gradient = this.createLinearGradient(x0, y0, x1, y1); for (var i = 0, len = _AN_Read_length('length', colors); i < len; i++ ){ gradient.addColorStop(ratios[i], colors[i]); } this.strokeStyle(gradient); return this; } , beginRadialGradientStroke: function (colors, ratios, x0, y0, r0, x1, y1, r1){ var gradient = this.createRadialGradient(x0, y0, r0, x1, y1, r1); for (var i = 0, len = _AN_Read_length('length', colors); i < len; i++ ){ gradient.addColorStop(ratios[i], colors[i]); } this.strokeStyle(gradient); return this; } , beginPath: function (){ this.context.beginPath(); return this; } , beginStroke: function (color){ this.strokeStyle(color); return this; } , bezierCurveTo: function (cp1x, cp1y, cp2x, cp2y, x, y){ this._dirty = true ; this.context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); return this; } , circle: function (x, y, radius){ this.arc(x, y, radius, 0, Math.PI * 2); return this; } , clearRect: function (x, y, width, height){ this._dirty = true ; this.context.clearRect(x, y, width, height); return this; } , clip: function (){ this._dirty = true ; this.context.clip(); return this; } , closePath: function (){ this._dirty = true ; this.context.closePath(); return this; } , createLinearGradient: function (x, y, width, height){ return this.context.createLinearGradient(x, y, width, height); } , createRadialGradient: function (x0, y0, r0, x1, y1, r1){ return this.context.createRadialGradient(x0, y0, r0, x1, y1, r1); } , ellipse: function (x, y, w, h){ var k = 0.5522848; var ox = (w / 2) * k; var oy = (h / 2) * k; var xe = x + w; var ye = y + h; var xm = x + w / 2; var ym = y + h / 2; this.moveTo(x, ym); this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); return this; } , fill: function (){ this._dirty = true ; this.context.fill(); return this; } , fillRect: function (x, y, width, height){ this._dirty = true ; this.context.fillRect(x, y, width, height); return this; } , fillStyle: function (color){ this.context.fillStyle = color; return this; } , font: function (font){ this.context.font = font; return this; } , globalAlpha: function (alpha){ this.context.globalAlpha = alpha; return this; } , globalCompositeOperation: function (operation){ this.context.globalCompositeOperation = operation; return this; } , lineCap: function (style){ this.context.lineCap = style; return this; } , lineDashOffset: function (offset){ this.context.lineDashOffset = offset; return this; } , lineJoin: function (join){ this.context.lineJoin = join; return this; } , lineWidth: function (width){ this.context.lineWidth = width; return this; } , miterLimit: function (limit){ this.context.miterLimit = limit; return this; } , lineTo: function (x, y){ this._dirty = true ; this.context.lineTo(x, y); return this; } , moveTo: function (x, y){ this.context.moveTo(x, y); return this; } , quadraticCurveTo: function (cpx, cpy, x, y){ this._dirty = true ; this.context.quadraticCurveTo(cpx, cpy, x, y); return this; } , rect: function (x, y, width, height){ this._dirty = true ; this.context.rect(x, y, width, height); return this; } , restore: function (){ this._dirty = true ; this.context.restore(); return this; } , rotate: function (angle){ this._dirty = true ; this.context.rotate(angle); return this; } , setStrokeStyle: function (thickness, caps, joints, miterLimit, ignoreScale){ if (typeof thickness === 'undefined') { thickness = 1; } if (typeof caps === 'undefined') { caps = 'butt'; } if (typeof joints === 'undefined') { joints = 'miter'; } if (typeof miterLimit === 'undefined') { miterLimit = 10; } ignoreScale = false ; this.lineWidth(thickness); this.lineCap(caps); this.lineJoin(joints); this.miterLimit(miterLimit); return this; } , save: function (){ this._dirty = true ; this.context.save(); return this; } , scale: function (x, y){ this._dirty = true ; this.context.scale(x, y); return this; } , scrollPathIntoView: function (){ this._dirty = true ; this.context.scrollPathIntoView(); return this; } , stroke: function (){ this._dirty = true ; this.context.stroke(); return this; } , strokeRect: function (x, y, width, height){ this._dirty = true ; this.context.strokeRect(x, y, width, height); return this; } , strokeStyle: function (style){ this.context.strokeStyle = style; return this; } , render: function (){ if (this._dirty) { if (this.game.renderType == Phaser.WEBGL) { PIXI.texturesToUpdate.push(this.baseTexture); } this._dirty = false ; } } } ; Phaser.BitmapData.prototype.mt = Phaser.BitmapData.prototype.moveTo; Phaser.BitmapData.prototype.lt = Phaser.BitmapData.prototype.lineTo; Phaser.BitmapData.prototype.at = Phaser.BitmapData.prototype.arcTo; Phaser.BitmapData.prototype.bt = Phaser.BitmapData.prototype.bezierCurveTo; Phaser.BitmapData.prototype.qt = Phaser.BitmapData.prototype.quadraticCurveTo; Phaser.BitmapData.prototype.a = Phaser.BitmapData.prototype.arc; Phaser.BitmapData.prototype.r = Phaser.BitmapData.prototype.rect; Phaser.BitmapData.prototype.cp = Phaser.BitmapData.prototype.closePath; Phaser.BitmapData.prototype.c = Phaser.BitmapData.prototype.clear; Phaser.BitmapData.prototype.f = Phaser.BitmapData.prototype.beginFill; Phaser.BitmapData.prototype.lf = Phaser.BitmapData.prototype.beginLinearGradientFill; Phaser.BitmapData.prototype.rf = Phaser.BitmapData.prototype.beginRadialGradientFill; Phaser.BitmapData.prototype.ef = Phaser.BitmapData.prototype.endFill; Phaser.BitmapData.prototype.ss = Phaser.BitmapData.prototype.setStrokeStyle; Phaser.BitmapData.prototype.s = Phaser.BitmapData.prototype.beginStroke; Phaser.BitmapData.prototype.ls = Phaser.BitmapData.prototype.beginLinearGradientStroke; Phaser.BitmapData.prototype.rs = Phaser.BitmapData.prototype.beginRadialGradientStroke; Phaser.BitmapData.prototype.dr = Phaser.BitmapData.prototype.rect; Phaser.BitmapData.prototype.dc = Phaser.BitmapData.prototype.circle; Phaser.BitmapData.prototype.de = Phaser.BitmapData.prototype.ellipse;