Check hit to start moving the position
This commit is contained in:
parent
abb6537480
commit
8f586169c1
@ -23,4 +23,5 @@ private:
|
|||||||
Vector2 mouseStart;
|
Vector2 mouseStart;
|
||||||
float len;
|
float len;
|
||||||
float ofset;
|
float ofset;
|
||||||
|
bool validHit = false;
|
||||||
};
|
};
|
||||||
|
@ -29,11 +29,12 @@ void App::update()
|
|||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||||
{
|
{
|
||||||
mouseStart = GetMousePosition();
|
mouseStart = GetMousePosition();
|
||||||
|
validHit = CheckCollisionPointRec(mouseStart, destA);
|
||||||
len = Vector2Distance(mouseStart, {destB.x, destB.y});
|
len = Vector2Distance(mouseStart, {destB.x, destB.y});
|
||||||
ofset = std::atan2(destB.x - mouseStart.x, destB.y - mouseStart.y);
|
ofset = std::atan2(destB.x - mouseStart.x, destB.y - mouseStart.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && validHit)
|
||||||
{
|
{
|
||||||
Vector2 mousePosition = GetMousePosition();
|
Vector2 mousePosition = GetMousePosition();
|
||||||
float dist = mousePosition.x - mouseStart.x;
|
float dist = mousePosition.x - mouseStart.x;
|
||||||
@ -44,7 +45,7 @@ void App::update()
|
|||||||
destA.y = newCenter.y + mousePosition.y;
|
destA.y = newCenter.y + mousePosition.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
|
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && validHit)
|
||||||
{
|
{
|
||||||
canvases[1 - pos].newGen();
|
canvases[1 - pos].newGen();
|
||||||
pos = 1 - pos;
|
pos = 1 - pos;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user