html - Easeljs 使用 mousemove 旋转对象

标签 html canvas rotation html5-canvas easeljs

我正在使用 HTML5 canvas + Easeljs

我想使用鼠标旋转应用程序中的对象。想法如下:单击一个对象>出现带有可拖动框的圆圈>将此框拖动到圆圈上使对象旋转。

这与 this one 有点相同的问题,但我不知道如何在 Easeljs 中执行此操作。

说明 Example

现在您可以通过单击右上角的按钮(L = 左,R = 右)来旋转对象,但我希望它像这样:

Example7

点击并拖动白色框将使其旋转

非常感谢您的帮助!

最佳答案

您必须将 mousedownmousemovemouseup< 的监听器添加到舞台(或者在您的情况下,可能是运动场形状)/。在 this example ,我只是监听全局 stagemouseupstagemousedownstagemousemove 事件。在触发 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

Check out this working example .

关于html - Easeljs 使用 mousemove 旋转对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38597682/

相关文章:

html - 为网站域设置默认主页

javascript - HTML 中的动态货币格式

android - 旋转后平移

javascript - 使用键盘箭头在 Canvas 上移动字符串

javascript - Canvas :在填充矩形顶部绘制线条

opencv - 查找两个摄像机之间的相对旋转

c - C中的旋转程序

javascript - 滚动后修复导航栏并平滑滚动下方的内容

html - IE中的多行按钮

javascript - 如何在 Canvas 中使用 rgba 颜色来更改具有条件的对象的颜色