gpt4 book ai didi

bitmap - EaselJS:有问题的拖/放

转载 作者:行者123 更新时间:2023-12-04 17:20:51 27 4
gpt4 key购买 nike

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

这是我的代码,所以你可以看到我有 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 之前添加一个额外的步骤:

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 设置为当前的鼠标位置,以防止形状/图像跳跃。

对于光标:
您可以通过 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
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

关于bitmap - EaselJS:有问题的拖/放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22829143/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com