Reputation: 11
Can anyone explain why, when both rectangles are placed in the same position, the red triangle jumps to an offset before rotating around its center?
//Create a stage by getting a reference to the canvas
stage = new createjs.Stage("demoCanvas");
//Create a Shape DisplayObject.
rect1 = new createjs.Shape();
rect1.graphics.beginFill("red").drawRect(0, 0, 40, 40);
rect1.regX = rect1.regY = 20; //rotate around center
rect1.alpha = .3;
rect2 = new createjs.Shape();
rect2.graphics.beginFill("green").drawRect(0, 0, 40, 40);
rect2.alpha = .3;
// place rectangles in the same position
rect1.x = rect1.y = rect2.x = rect2.y = 100;
//Add Shape instance to stage display list.
stage.addChild(rect1,rect2);
createjs.Ticker.setFPS(60);
createjs.Ticker.addEventListener("tick", onTick);
function onTick() {
rect1.rotation++;
stage.update();
}
What regX, regY values need to be provided to keep it in place overlaying the green?
(The 2013 answer provided did not show the original position)
Thanks, Steve
Upvotes: 1
Views: 1559
Reputation: 43
That's supposed to happen; work around it by adding the regX/regY values to the position of the rotating rect. rect1.x = rect1.y = 120; rect2.x = rect2.y = 100;
Upvotes: 1