オブジェクトを回転させたい位置にグラフィック コンテナーを描画し、その中心がグラフィックの x/y 位置になるようにオブジェクトを描画する必要があります。そのため、中心を中心にピボットしながら希望する正確な座標に描画される長方形を描画するには、この関数を使用します。
self.createRect = function (x1, y1, x2, y2, color) {
var graphics = new PIXI.Graphics();
graphics.beginFill(color || 0x000000);
//This is the point around which the object will rotate.
graphics.position.x = x1 + (x2/2);
graphics.position.y = y1 + (y2/2);
// draw a rectangle at -width/2 and -height/2. The rectangle's top-left corner will
// be at position x1/y1
graphics.drawRect(-(x2/2), -(y2/2), x2, y2);
self.stage.addChild(graphics);
return graphics;
};
これは正方形または長方形なので、x1 + (幅/2) と y1 + (高さ/2) を使用して画面上の中心を計算し、長方形を左と上に半分ずつオフセットします。 drawRect(-(width/2), -(height/2), x2, y2); を使用して、その幅と高さの半分。