1
General / Clamp to Screen
« on: April 27, 2011, 04:04:36 am »
Hello!
This is my first time posting and I'm in a bit of a pickle. I started to use SFML for a game and I'm working on the basics of the library. Now, I'm probably totally missing something here but is their a way to bind a character to the screen? As in not allow them to go off screen?
In XNA their is a function called Clamp that is used to do this and I tried to recreate it here but it doesn't work.
Any help would be much appreciated. As I said, I'm probably just not seeing the obvious answer.[/code]
This is my first time posting and I'm in a bit of a pickle. I started to use SFML for a game and I'm working on the basics of the library. Now, I'm probably totally missing something here but is their a way to bind a character to the screen? As in not allow them to go off screen?
In XNA their is a function called Clamp that is used to do this and I tried to recreate it here but it doesn't work.
Code: [Select]
float Clamp(float value, float min, float max)
{
if(value < min)
{
return min;
}
if(value > max)
{
return max;
}
if(min <= value || value >= max)
{
return value;
}
}
//in game loop
playerPositionX = Clamp(playerPositionX, 0, windowWidth);
playerBoundingBoxY = Clamp(playerPositionY, 0, windowHeight);
Any help would be much appreciated. As I said, I'm probably just not seeing the obvious answer.[/code]