【问题标题】:easeljs rotating a shape around its center - gets offset画架围绕其中心旋转形状 - 得到偏移
【发布时间】:2015-11-06 09:48:09
【问题描述】:

谁能解释一下为什么当两个矩形放置在同一位置时,红色三角形会在围绕其中心旋转之前跳转到一个偏移量?

//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();
}

jsfiddle

需要提供哪些 regX、regY 值才能将其保持在覆盖绿色的位置?

(提供的 2013 年答案未显示原始位置)

谢谢, 史蒂夫

【问题讨论】:

  • 你必须通过改变变量来尝试一下并推断它是如何工作的。您无法通过设置正确的 regX 和 regY 值来解决它,但您必须更改矩形的起始位置

标签: javascript html5-canvas easeljs createjs


【解决方案1】:

这是应该发生的;通过将 regX/regY 值添加到旋转矩形的位置来解决它。 rect1.x = rect1.y = 120; rect2.x = rect2.y = 100;

【讨论】:

    猜你喜欢
    • 2018-05-17
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 2014-04-21
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多