开发者

ActionScript - Inaccurate Mouse Coordinates?

开发者 https://www.devze.com 2023-03-24 06:25 出处:网络
when tracing the mouseX / mouseY or localX / localY coordinates of a display object, why does x start at 1 while y starts at 0?

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 simpl开发者_StackOverflowe 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号