I'm building a program, and need a function to check if the mouse is on an object. I wrote the function and created a new .hpp-File, because multiple Files in my project will use the function. The File is called HitboxDetec.hpp
. The function I wrote in it looks like this:
bool isClicked(sf::Sprite* Sprite, sf::RenderWindow* pW)
{
int MOUSE_X = sf::Mouse::getPosition(*pW).x;
int MOUSE_Y = sf::Mouse::getPosition(*pW).y;
if (MOUSE_X >= Sprite->getPosition().x &&
MOUSE_X <= Sprite->getPosition().x + Sprite->getPosition().x + 500 &&
MOUSE_Y >= Sprite->getPosition().y &&
MOUSE_Y <= Sprite->getPosition().y + Sprite->getPosition().y + 500)
{
return true;
}
else return false;
}
I included the needed libraries etc. and the code works (I tested it by declaring the function in my .cpp-File).
In my .cpp File I included the CookieDetec.hpp
-File, and called it with
if(isClicked(pSprite, pW)) {Stuff}
When I compile my program, it just gives me a LNK2005-Error. How can I fix this?