在 Animate CC 2017 中使用 easeljs 拖放

2022-01-11 00:00:00 drag-and-drop javascript flash createjs

我一直在使用 Adob​​e Animate CC 2015.2 中的 HTML Canvas 项目在舞台上拖动电影剪辑,使用 creatjs 鼠标交互教程.我在工作时在运行 OS X Yosemite 的 MacBook Pro 上执行此操作.

I've been using an HTML Canvas project in Adobe Animate CC 2015.2 to drag around a movieClip on the stage, using the method recommended in the creatjs Mouse Interaction Tutorial. I was doing this on a MacBook Pro running OS X Yosemite at work.

这是我使用的代码,它运行良好.影片剪辑位于时间轴第一帧的舞台上,动作也在同一帧中.movieClip 实例 (my_mc) 跟随鼠标移动 - 到目前为止一切顺利.

Here is the code I used and it worked fine. The movieClip is on the stage in the first frame of the timeline and the actions are in that same frame. The movieClip instance (my_mc) follows the mouse around - so far so good.

this.my_mc.on("pressmove", function(evt){
    evt.currentTarget.x = evt.stageX;
    evt.currentTarget.y = evt.stageY;
});

但是,在两个朋友的配备 Retina 显示屏并运行 macOS Sierra 的 MacBook Pro 上尝试在 Animate CC 2017 中完全相同的示例,会导致鼠标位置和影片剪辑位置之间出现奇怪而显着的偏移.鼠标距离舞台原点 (0,0) 越远,偏移越大.

However, trying the exact same example in Animate CC 2017 on two friends' MacBook Pros with Retina Display running macOS Sierra, results in there being a strange and significant offset between the position of the mouse and the position of the movieClip. The offset is bigger the further away the mouse moves from the origin (0,0) of the stage.

有谁知道为什么会发生这种情况或能想到解决方法吗?我尝试使用 globalToLocal 进行一些修改,但这并不能解决问题.

Does anyone know why this is happening or can think of a workaround? I've tried a few modifications using globalToLocal, but this does not solve the problem.

我能想到的三个主要原因是:

The three main reasons I can think of are:

  • Animate CC 2017 中的一些变化导致了这个问题
  • Retina 显示屏导致问题
  • macOS Sierra 导致问题

欢迎任何想法或解决方法.

Any thoughts or workarounds are welcome.

提前致谢,

戴夫

推荐答案

我想我已经解决了这个问题.无论操作系统和显示分辨率如何,以下似乎都适用于 Animate CC 2015.2 和 Animate CC 2017.

I think I've sorted the problem. The following seems to work on both Animate CC 2015.2 and Animate CC 2017 irrespective of OS and display resolution.

this.my_mc.on("pressmove", function(evt){
    var p = stage.globalToLocal(evt.stageX, evt.stageY);
    evt.currentTarget.x = p.x;
    evt.currentTarget.y = p.y;
});

我仍然需要弄清楚为什么在 Animate 2017 中而不是在 Animate CC 2015.2 中需要进行更改(抓挠头).

I still have to get my head around why the change was necessary in Animate 2017 and not in Animate CC 2015.2 (scratches head).

谢谢,

戴夫

相关文章