动作 - 不准确的鼠标坐标?鼠标、坐标、不准确、动作

2023-09-08 13:18:37 作者:愿你常欢笑别皱眉别再想他

跟踪 mouseX / mouseY的 localX / localY 坐标显示对象,为什么 X 从1开始,而从0开始?

例如,我画一个简单的400×400像素的精灵到了的MouseEvent.MOUSE_MOVE 事件侦听器调用一个处理功能来跟踪本地坐标阶段的鼠标。

第一,左上角的像素返回 {X:1,Y:0} 最后,右下角的像素返回 {X :400,Y:399} 。不能同时在 X 启动和具有相同值结束?我不知道这更有意义的第一个鼠标的坐标(0或1),但它肯定是没有意义的,他们有什么不同?

  [SWF(宽度=1000,高度=600的backgroundColor =0xCCCCCC)

进口flash.display.Sprite;
进口flash.events.MouseEvent;

VAR darkBlueRect:雪碧= createSprite();
darkBlueRect.x = 23;
darkBlueRect.y = 42;
的addChild(darkBlueRect);

darkBlueRect.addEventListener(的MouseEvent.MOUSE_MOVE,mouseMoveEventHandler);

功能mouseMoveEventHandler(EVT:MouseEvent)方法:无效
{
    跟踪(darkBlueRect.mouseX,evt.localX,darkBlueRect.mouseY,evt.localY);
}

功能createSprite():雪碧
{
    VAR结果:雪碧=新的Sprite();
    result.graphics.beginFill(0x0000FF,0.5);
    result.graphics.drawRect(0,0,400,400);
    result.graphics.endFill();

    返回结果;
}
 

解决方案

报告错误,你发现之一:

如何在Flash舞台中输出鼠标的坐标

http://bugs.adobe.com/flashplayer/

我想也许这是为了腾出空间用于除其他事项外精灵行,但所有这些测试证明并非如此。这一点,在我看来,一个bug。文件它,我将第二,或者,如果你不能打扰,让我知道我会提交它,因为它应该是固定的。

更新

我刚刚试过另一项测试,我设置了一个StageScaleMode允许缩放,然后在2-3次的对象放大,并试图获得0/0阅读MOUSE_DOWN。只是不能明显地做。我没有得到一个0读数的X终于但随后Y是出来。我想这个问题可能回落到闪烁一个号码,而不是一个int返回X / Y指针位置的事实,你可以得到的指针位置十进制值,你会发现,如果你正在放大。也许这是只是马车code或将其归结为基于怎样的小数点计算浮点precision问题,或者如果你没有放大和不缩放对象,闪弹,十进制值关闭的诠释这也可以解释的怪异行为。不知道只是猜测,以为我会加入这个额外的测试结果。

when tracing the mouseX / mouseY or localX / localY coordinates of a display object, why does x start at 1 while y starts at 0?

for example, i've drawn a simple 400 x 400 pixel sprite onto the stage with a MouseEvent.MOUSE_MOVE event listener that calls a handler function to trace the local coordinates of the mouse.

the first, top-left pixel returns {x:1, y:0} and the last, bottom-right pixel returns {x:400, y:399}. shouldn't both the x and y start and end with the same value? i'm not sure which makes more sense for a the first mouse coordinate (either 0 or 1) but it certainly doesn't make sense that they are different?

[SWF(width = "1000", height = "600", backgroundColor = "0xCCCCCC")]

import flash.display.Sprite;
import flash.events.MouseEvent;

var darkBlueRect:Sprite = createSprite();
darkBlueRect.x = 23;
darkBlueRect.y = 42;
addChild(darkBlueRect);

darkBlueRect.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveEventHandler);

function mouseMoveEventHandler(evt:MouseEvent):void
{
    trace(darkBlueRect.mouseX, evt.localX, darkBlueRect.mouseY, evt.localY);
}

function createSprite():Sprite
{
    var result:Sprite = new Sprite();
    result.graphics.beginFill(0x0000FF, 0.5);
    result.graphics.drawRect(0, 0, 400, 400);
    result.graphics.endFill();

    return result;
}

解决方案

Report a bug, you've found one:

http://bugs.adobe.com/flashplayer/

I thought perhaps it was to make room for a line applied to the sprite among other things but all those tests proved not to be the case. This is, in my opinion, a bug. File it and I'll second it, or if you can't be bothered let me know I'll file it cause it should be fixed.

Update

I've just tried another test where I set the stageScaleMode to allow for scaling, then zoomed in 2-3 times to the object and tried to get a 0/0 reading on MOUSE_DOWN. Just can't be done apparently. I did get a 0 reading on the X finally but then the Y is out. I think this issue may come down to the fact that flash returns X/Y pointer position as a Number and not an int, and you can get decimal values on the pointer position as you'll notice if you're zoomed in. Perhaps it's just buggy code or it comes down to floating point precision issues based on how the decimal points are calculated, or if you're not zoomed in and the object isn't scaled, flash rounds that decimal value off an int and this may also explain the weird behavior. Dunno just guessing, thought I'd add the results of this extra test.