DirectX移动我的GUI

时间:2015-05-03 00:00:58

标签: c++ math directx

我正在为我的一个朋友创建一个叠加层,我想实现所以当我按住鼠标左键时我可以动态移动我的盒子。 这是我目前的方法:

    if (mouse.isClicked() && (cursor.x >= mainGUIBox.x) && (cursor.x < (mainGUIBox.x+mainGUIBox.w)) &&
                             (cursor.y >= mainGUIBox.y) && (cursor.y < (mainGUIBox.y+40)))
    {
        DrawString("CLICKED BOX", 500, 500, 255, 0, 0, ppFont);
        float xxxx = cursor.x-(mainGUIBox.x+cursor.x);
        float yyyy = cursor.y-(mainGUIBox.y+cursor.y);
        mainGUIBox.x = xxxx;
        mainGUIBox.y = yyyy;

    } // Move MainGUI

但是这种方法不起作用,只要我点击框移动它就会在我的屏幕外拍摄:P

我在数学上非常糟糕,而且我无法找到一个很好的方程式来动态地找出它并在我的鼠标之后将它对齐。

由于

1 个答案:

答案 0 :(得分:1)

cursor.x - (mainGUIBox.x + cursor.x)

相同
cursor.x - mainGUIBox.x - cursor.x

- mainGUIBox.x

单击该框时,其坐标将变为负数,可能位于屏幕之外。