Created
March 28, 2014 19:47
-
-
Save ada-lovecraft/9841545 to your computer and use it in GitHub Desktop.
Extend Sprite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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