I'm thinkin it gets the variables messed up because it causes large variable changing sections of code to be skipped.I tried making it local but that didn't work.I did however find out that moving that calling function fixes it.It would be good though to know why this changes anything.
So I moved it directly past the function it was skipping the rest of.
bool click(int left,int top,int width,int height)
{
if(Mouse::isButtonPressed(Mouse::Left))
{
if(IntRect(left,top,width,height).contains(MPosition.x,MPosition.y))
{
if(released)
{
released=false;
//playsound() was here
return true;
}
}
else
{
if(released)
{
}
}
released=false;
}
else
{
released=true;
return false;
}
}
void loop()
{
MPosition=window.mapPixelToCoords(Mouse::getPosition(window));
if(room==1)
{
if(leave)
tback.loadFromFile("1.png");
leave=false;
if(click(501,256,104,54))//click function
{
playsound(0,"room.wav");//moved to here
room=2;
leave=true;
}
}
}