我正在使用最新版本的运动to,现在我正在做益智游戏,它要求我的拼图块在置乱后旋转,有谁知道如何旋转不同的角度,而不是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/
发布于 2014-09-09 08:05:13
代码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 ),https://stackoverflow.com/questions/25739426
复制相似问题