Skip to content

Instantly share code, notes, and snippets.

@EvidentlyCube
Last active August 29, 2015 14:19
Show Gist options
  • Save EvidentlyCube/8311df192779c15d4a3f to your computer and use it in GitHub Desktop.
Save EvidentlyCube/8311df192779c15d4a3f to your computer and use it in GitHub Desktop.
Phaser augments by Retrocade.net
(function(Phaser, PIXI){
var defineFor = function(classDef){
classDef.prototype.positionCenter = function(){
this.center = Phaser.GAMES[0].width / 2;
};
classDef.prototype.positionMiddle = function(){
this.middle = Phaser.GAMES[0].height / 2;
};
classDef.prototype.positionCenterParent = function(){
if (this.parent !== null){
this.center = this.parent.x + this.parent.width / 2;
}
};
classDef.prototype.positionMiddleParent = function(){
if (this.parent !== null){
this.middle = this.parent.y + this.parent.height / 2;
}
};
};
defineFor(Phaser.Sprite);
defineFor(Phaser.Text);
defineFor(PIXI.DisplayObjectContainer);
})(Phaser, PIXI);
(function(Phaser, PIXI){
var defineFor = function(classDef){
Object.defineProperty(classDef.prototype, "right", {
get: function () {
return this.x + this.width - 1;
},
set: function (value) {
this.x = value - this.width + 1 | 0;
}
});
Object.defineProperty(classDef.prototype, "bottom", {
get: function () {
return this.y + this.height - 1;
},
set: function (value) {
this.y = value - this.height + 1 | 0;
}
});
};
defineFor(Phaser.Text);
defineFor(PIXI.DisplayObjectContainer);
})(Phaser, PIXI);
(function(Phaser, PIXI){
var defineFor = function(classDef){
Object.defineProperty(classDef.prototype, "center", {
get: function () {
return this.x + this.width / 2;
},
set: function (value) {
this.x = value - this.width / 2 | 0;
}
});
Object.defineProperty(classDef.prototype, "middle", {
get: function () {
return this.y + this.height / 2;
},
set: function (value) {
this.y = value - this.height / 2 | 0;
}
});
};
defineFor(Phaser.Sprite);
defineFor(Phaser.Text);
defineFor(PIXI.DisplayObjectContainer);
})(Phaser, PIXI);
(function(Phaser, PIXI){
var defineFor = function(classDef){
classDef.prototype.globalToLocalX = function(x, localObject){
while (localObject) {
x -= localObject.x;
localObject = localObject.parent;
}
return x;
};
classDef.prototype.globalToLocalY = function(y, localObject){
while (localObject) {
y -= localObject.y;
localObject = localObject.parent;
}
return y;
};
};
defineFor(Phaser.Sprite);
defineFor(Phaser.Text);
defineFor(PIXI.DisplayObjectContainer);
})(Phaser, PIXI);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment