EaselJS:故障拖放 [英] EaselJS: glitchy drag/drop

查看:12
本文介绍了EaselJS:故障拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个容器内的位图.当我拖动容器时,光标变为编辑文本形状,并且图像也跳到光标的右下角(就好像我从左上角按住图像并拖动它一样).

I have a bitmap inside of a container. When I drag the container the cursor changes to the edit-text shape, and also the image jumps to the bottom-right side of the cursor (as though I'm holding the image from the top-left corner and dragging it).

这是我的代码,您可以看到我有 RTFM:

Here's my code just so you can see that I've RTFM:

function createIcon(imgPath) {
    var image = new Image();
    image.onload = function () {
        var img = new createjs.Bitmap(event.target)

        var con = new createjs.Container();
        con.x = 160;
        con.y = 100;
        con.addChild(img);
        stage.addChild(con);

        con.on("pressmove", function(evt) {
            evt.currentTarget.x = evt.stageX;
            evt.currentTarget.y = evt.stageY;
            stage.update();
        });

        stage.update();
    }

    image.src = imgPath;
}

有什么想法吗?

推荐答案

为了防止跳跃,你必须在 pressmove 之前添加一个额外的步骤:

To prevent the jumping you would have to add an additional step before the pressmove:

con.on('mousedown', function(evt) {
    var ct = evt.currentTarget,
        local = ct.globalToLocal(evt.stageX, evt.stageY),
        nx = ct.regX - local.x,
        ny = ct.regY - local.y;
    //set the new regX/Y
    ct.regX = local.x;
    ct.regY = local.y;
    //adjust the real-position, otherwise the new regX/Y would cause a jump
    ct.x -= nx;
    ct.y -= ny;
});

这会将新的 regX/Y 设置为当前的鼠标位置,以防止形状/图像跳跃.

This will set the new regX/Y to the current's mouse-position to prevent the shape/image from jumping.

对于光标:您可以通过 CSS 进行设置:

For the cursor: You could either set this via CSS:

canvas {
    cursor: default !important; /* in this case you couldn't set any other cursor via EaselJS though */
}

或者您可以通过 EaselJS 进行设置:http://www.createjs.com/Docs/EaselJS/classes/DisplayObject.html#property_cursor

OR you can set this via EaselJS: http://www.createjs.com/Docs/EaselJS/classes/DisplayObject.html#property_cursor

con.cursor = "default"; //or 'pointer'...or whatever cursor you want it to be
// you have to activate enableMouseOver though on the stage for this to work

这篇关于EaselJS:故障拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆