0
我試圖獲得應用regX
,regY
和rotation
的DisplayObject
的全局座標。考慮以下幾點:旋轉後的全局X和Y
function drawShapes(){
function createRectangle(color){
var rect = new createjs.Shape();
rect.graphics.beginFill(color).drawRect(0, 0, 100, 100);
stage.addChild(rect);
return rect;
}
var rect1 = createRectangle("rgba(255, 0, 0, 1)");
rect1.x = 100;
rect1.y = 100;
var ltg = rect1.localToGlobal(0, 0);
console.log(`rect1 x: ${rect1.x}, y: ${rect1.y}, globalX: ${ltg.x}, globalY: ${ltg.y}`);
var rect2 = createRectangle("rgba(0, 255, 0, 1)");
rect2.x = 100;
rect2.y = 100;
rect2.regX = 50;
rect2.regY = 50;
ltg = rect2.localToGlobal(0, 0);
console.log(`rect2 x: ${rect2.x}, y: ${rect2.y}, globalX: ${ltg.x}, globalY: ${ltg.y}`);
var rect3 = createRectangle("rgba(0, 0, 255, 1)");
rect3.x = 100;
rect3.y = 100;
rect3.regX = 50;
rect3.regY = 50;
rect3.rotation = 45;
ltg = rect3.localToGlobal(0, 0);
console.log(`rect3 x: ${rect3.x}, y: ${rect3.y}, globalX: ${ltg.x}, globalY: ${ltg.y}`);
stage.update();
}
的這個輸出是:
rect1 x: 100, y: 100, globalX: 100, globalY: 100
這顯然是有道理的
rect2 x: 100, y: 100, globalX: 50, globalY: 50
這是有道理太,綠色的矩形移動50個像素並左
rect3 x: 100, y: 100, globalX: 100, globalY: 29.289321881345245
這讓我感到困惑。它應該和rect2一樣。它似乎旋轉了,不管regX
和regY
我誤解了一些東西,或者在createjs中有錯誤/ WAI。無論如何,是否有解決方法?