Skip to content

Instantly share code, notes, and snippets.

@ada-lovecraft
Created March 28, 2014 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ada-lovecraft/9841545 to your computer and use it in GitHub Desktop.
Save ada-lovecraft/9841545 to your computer and use it in GitHub Desktop.
Extend Sprite
'use strict';
var Block = function(x, y, size, color ) {
this.size = size;
this.color = color;
this.bmd = game.add.bitmapData(this.size, this.size);
this.createTexture();
Phaser.Sprite.call(this, game, x, y, this.bmd);
// initialize your prefab here
};
Block.prototype = Object.create(Phaser.Sprite.prototype);
Block.prototype.constructor = Block;
Block.prototype.setColor = function(color) {
this.color = color;
this.createTexture();
}
Block.prototype.createTexture = function() {
this.bmd.clear();
this.bmd.ctx.beginPath();
this.bmd.ctx.rect(0,0,this.size,this.size);
this.bmd.ctx.fillStyle = this.color;
this.bmd.ctx.fill();
this.bmd.ctx.closePath();
this.bmd.render();
this.bmd.refreshBuffer();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment