繁体   English   中英

KineticJs 不同角度旋转

[英]KineticJs different angle rotation

我正在使用最新版本的 kineticJs,现在我在做益智游戏,这需要我的拼图在打乱后旋转,有人知道如何旋转不同的角度而不是 2-3 个相同角度的旋转吗? 谢谢 :)

                    fillPatternImage:imageObj,
                    fillPatternOffsetX :i * pieceWidth,
                    fillPatternOffsetY :j * pieceHeight,
                    stroke: "#000000",
                    strokeWidth: 4,
                    lineCap: "round",
        rotation : Math.PI * 28.5 * Math.floor(Math.random() * 2), <-- rotation part
                    draggable: true,
  offset : [ pieceWidth / 2 + pieceWidth * 0.3,pieceHeight / 2 + pieceHeight * 0.3 ],
                x:0+ (Math.random()*6)*((stage.getWidth()+pieceWidth)/16),
                y:0+ (Math.random()*4)*((stage.getHeight()+pieceHeight)/16),

我的小提琴: http : //jsfiddle.net/e70n2693/34/

代码Math.floor(Math.random() * 2)给出 0 或 1,然后乘以 PI*28.5,给出 0 或 PI*28.5 的旋转。

Math.random()的乘数增加到所需的可能旋转次数。

您可能还需要更改乘以 PI 的值,以便更好地扩展可能的角度(减少它)

像下面这样的应该给出更广泛的结果

var numberOfDifferentAngles = 50;
var differenceBetweenAngles = Math.PI * 2;

rotation : differenceBetweenAngles  
   * Math.floor(Math.random() * numberOfDifferentAngles ),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM