Skip to content

Instantly share code, notes, and snippets.

@afarber
Created November 26, 2016 15:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save afarber/78ecbbc72c493e2e7e4e439412814772 to your computer and use it in GitHub Desktop.
"use strict";
function Score(color) {
PIXI.Container.call(this);
this.color = color;
this.interactive = false;
this.buttonMode = false;
this.visible = false;
this.bgGraphics = new PIXI.Graphics();
this.addChild(this.bgGraphics);
this.text = new PIXI.Text('XXX', {font: '20px Arial', fill: 0xFFFFFF});
this.text.x = 2;
this.text.y = 1;
this.addChild(this.text);
//this.filters = [ new PIXI.filters.DropShadowFilter() ];
//this.filters[0].alpha = .2;
}
Score.prototype = Object.create(PIXI.Container.prototype);
Score.prototype.constructor = Score;
Score.WIDTH = 18;
Score.HEIGHT = 24;
Score.POLY_1 = [
new PIXI.Point(0, 0),
new PIXI.Point(Score.WIDTH + 2, 0),
new PIXI.Point(Score.WIDTH - 2, Score.HEIGHT / 2),
new PIXI.Point(Score.WIDTH + 2, Score.HEIGHT),
new PIXI.Point(0, Score.HEIGHT)
];
Score.POLY_2 = [
new PIXI.Point(0, 0),
new PIXI.Point(1.5 * Score.WIDTH + 2, 0),
new PIXI.Point(1.5 * Score.WIDTH - 2, Score.HEIGHT / 2),
new PIXI.Point(1.5 * Score.WIDTH + 2, Score.HEIGHT),
new PIXI.Point(0, Score.HEIGHT)
];
Score.POLY_3 = [
new PIXI.Point(0, 0),
new PIXI.Point(2.2 * Score.WIDTH + 2, 0),
new PIXI.Point(2.2 * Score.WIDTH - 2, Score.HEIGHT / 2),
new PIXI.Point(2.2 * Score.WIDTH + 2, Score.HEIGHT),
new PIXI.Point(0, Score.HEIGHT)
];
Score.prototype.setText = function(score) {
this.text.text = score;
// TODO var rect = this.text.getBounds();
this.bgGraphics.clear();
this.bgGraphics.beginFill(this.color, 1);
if (score < 10) {
this.bgGraphics.drawPolygon(Score.POLY_1);
} else if (score < 100) {
this.bgGraphics.drawPolygon(Score.POLY_2);
} else {
this.bgGraphics.drawPolygon(Score.POLY_3);
}
this.bgGraphics.endFill();
}
Score.prototype.getCenterX = function() {
return this.x + Score.WIDTH / 2;
}
Score.prototype.getCenterY = function() {
return this.y + Score.HEIGHT / 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment