2016-08-20 11 views
0

下に四角形を描画:例えばI青(又は赤)長方形上記白色数としてスコアを描画しようとしている単語ゲームでPIXI.Text

screenshot

、上記のスクリーンショットであります数字「13」。ここで

(現在はハードコードWIDTHHEIGHTと)私のクラス全体Score.jsです:

"use strict"; 

function Score(color) { 
     PIXI.Container.call(this); 

     this.interactive = false; 
     this.buttonMode = false; 
     this.visible = false; 

     this.bgGraphics = new PIXI.Graphics(); 
     this.bgGraphics.beginFill(color, 1); 
     this.bgGraphics.drawRect(0, 0, Score.WIDTH, Score.HEIGHT); 
     this.bgGraphics.endFill(); 
     this.addChild(this.bgGraphics); 

     this.text = new PIXI.Text('XXX', {font: '20px Arial', fill: 0xFFFFFF}); 
     this.text.x = 1; 
     this.text.y = 1; 
     this.addChild(this.text); 
} 

Score.prototype = Object.create(PIXI.Container.prototype); 
Score.prototype.constructor = Score; 

Score.WIDTH = 36; 
Score.HEIGHT = 24; 

Score.prototype.setText = function(str) { 
     this.text.text = str; 
} 

私は新しい矩形が各呼び出し上に描画されるように、私のsetText()機能を変更する方法を、不思議 - 境界としてstr引数の長方形ですか?

私はPIXI.Text.getBounds()方法を見てきたが、それは、私はあなただけthis.text.widthを使用することができると思うMatrixなくRectangle ...

答えて

1

を返します。これは歴史的にはbugs associated with itでしたが、最新のバージョンで正しく動作するはずです。

関連する問題