Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - deexener

Pages: [1]
1
General / Clamp to Screen
« on: April 27, 2011, 05:49:15 am »
Thanks for the reply! And thanks for pointing out my mistakes >.<

But I'm still not able to get it working correctly. I did change the function and the playerBoundingBoxY is supposed to be playerPositionY, thought code::blocks auto-entered the correct one while typing. my bad.


even after those corrections i'm still able to travel outside the window. I'll keep at it and try it in a new project because my code is a mess of different tutorials right now.

2
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.

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]

Pages: [1]
anything