拖动容器的子容器时 mouseX/Y 混乱
我有一个图像网格,它们被添加到类中的图像容器(Sprite)中。 当我单击按钮时,图像容器会补间(缩放)为 0.2 现在我想开始拖动图像。鼠标按下时,我添加一个 EnterFrame 事件:
function onEnterFrame(e:Event):void
{
imagecontainer.image.x = this.mouseX;
imagecontainer.image.y = this.mouseY;
}
不幸的是,图像永远不会在鼠标位置上,但与鼠标指针的偏移量会增加/减少。 另一种方法 startDrag/stopDrag 效果很好,但我仍然需要 mouseX/mouseY 将图像放置在网格上...... 我也尝试过parent.mouseX,但没有成功。 为什么会发生这种情况?我认为 mouseX/mouseY 始终取决于舞台尺寸。
I've got a grid of images which are added to a imagecontainer(Sprite) in a class.
When I click a button, the imagecontainer gets tweened(scaled) to 0.2
Now I would like to start dragging around the images. on mouse-down I add an enterFrame Event:
function onEnterFrame(e:Event):void
{
imagecontainer.image.x = this.mouseX;
imagecontainer.image.y = this.mouseY;
}
Unfortunately the image is never on the mouseposition but has a increasing/decreasing offset to the mouse pointer.
The alternative, startDrag/stopDrag works perfectly, but I still need the mouseX/mouseY for placing the image on a grid…
I tried also parent.mouseX, no luck with that.
Why is this happening? I thought mouseX/mouseY is always depending on the stage-dimension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想获取相对于舞台上鼠标位置的
mouseX
和mouseY
那么为什么不使用:另外,如果您放大一些东西(假设总大小为 200%),那么舞台上的 50 像素实际上是已缩放的容器中的 25 像素。
使用它作为文档类来看看我的意思:
If you want to get the
mouseX
andmouseY
relative to the mouse position on thestage
then why don't you use:Also, if you scale something up (let's say to a total size of 200%), then 50 pixels across on the stage is actually 25 pixels across in the container that has been scaled.
Use this as a document class to see what I mean:
如果您仍在寻找这个,也许您可以使用 startDrag();和 stopDrag();
用于拖动图像。
像这样:
更新:您可以像这样设置你的函数:
If you are still looking for this maybe you can use startDrag(); and stopDrag();
for dragging images.
like this:
Update : You can set ur function like this:
你试过吗:
have you tried: