我正在使用 HTML5 canvas + Easeljs
我想使用鼠标旋转应用程序中的对象。想法如下:单击一个对象>出现带有可拖动框的圆圈>将此框拖动到圆圈上使对象旋转。
这与 this one 有点相同的问题,但我不知道如何在 Easeljs 中执行此操作。
说明
现在您可以通过单击右上角的按钮(L = 左,R = 右)来旋转对象,但我希望它像这样:
点击并拖动白色框将使其旋转
非常感谢您的帮助!
最佳答案
您必须将 mousedown
、mousemove
和 mouseup< 的监听器添加到舞台(或者在您的情况下,可能是运动场形状)/
。在 this example ,我只是监听全局 stagemouseup
、stagemousedown
和 stagemousemove
事件。在触发 stagemousedown
之前,我不会分配 stagemousemove
监听器。然后,当 stagemouseup
被触发时,我将其删除。
对于每个 stagemousemove
事件,您需要找到玩家与舞台鼠标位置之间的角度。您可以使用以下公式来执行此操作,其中 shape
是您的玩家:
var angleInRadians = Math.atan2(stage.mouseY - shape.y, stage.mouseX - shape.x);
var angleInDegrees = angleInRadians * (180 / Math.PI);
然后您只需设置shape.rotation = angleInDegrees
。
关于html - Easeljs 使用 mousemove 旋转对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38597682/