0

在 win2D 中,Get absolute mouse position 是这个(来自 Win2D Sprite Sample)

var point = e.GetCurrentPoint((UIElement)sender).Position.ToVector2();

但是,这是绝对位置,

我做鼠标是否指向游戏玩家

所以,我制作了这个代码,但它不起作用。

        var rpoint = e.GetCurrentPoint(canvas).Position.ToVector2();



        // 사각형 길을 보여주기  
        if ((rpoint.X > wizardPosition.X - 64) && (rpoint.X < wizardPosition.X + 64) && (rpoint.Y > wizardPosition.Y - 150) && (rpoint.Y < wizardPosition.Y + 42) )
        {
            if (ShowBorder == true) { ShowBorder = false; }

             else if (ShowBorder == false)
                ShowBorder = true; 
        }

有人解决了这个问题吗?

4

1 回答 1

0

我自己解决了。反正。代码是这样的

            var rpoint = e.GetCurrentPoint(this).Position.ToVector2();


        // Invert the display transform, to convert pointer positions into simulation rendertarget space.
        Matrix3x2 Mtransform;
        Matrix3x2.Invert(transform, out Mtransform);

        var xpoint = Vector2.Transform(rpoint, Mtransform);

        // 사각형 길을 보여주기  
        if ((xpoint.X > wizardPosition.X - 64) && (xpoint.X < wizardPosition.X + 64) && (xpoint.Y > wizardPosition.Y - 150) && (xpoint.Y < wizardPosition.Y + 42) )
        {
            if (ShowBorder == true) { ShowBorder = false; }

             else if (ShowBorder == false)
                ShowBorder = true; 
        }
于 2017-07-04T16:20:30.440 回答