SFML community forums

Help => Window => Topic started by: Bleemo on February 22, 2013, 06:36:55 pm

Title: Can't Send Mouse/Rectangle Coordinates to Function
Post by: Bleemo on February 22, 2013, 06:36:55 pm
I hope this is in the right forum.

I'm attempting to send the mouse position and a sprite position, as well as create a rectangle object with the sprite position in a member function on call, then produce movement from a mouse click when the rectangle is clicked on, but for some reason it won't accept the coordinates.

In int main() before loop
// Object creation
Warrior warrior;
warrior.setWarrior(288,672);

// Mouse position
        float mPosX = sf::Mouse::getPosition(gameWindow).x,
                  mPosY = sf::Mouse::getPosition(gameWindow).y;

// Sprite position
        float warPos[4] = {
                  warrior.warrior.getPosition().x,
                  warrior.warrior.getPosition().y,
                  warrior.warrior.getGlobalBounds().width,
                  warrior.warrior.getGlobalBounds().height };

In class
// Class member function prototype
void moveWar(float Px, float Py, float Gx, float Gy, float Mx, float My);

// Class member function
void Warrior::moveWar(float Px, float Py, float Gx, float Gy, float Mx, float My)
{
        sf::IntRect warRect(Px, Py, Gx, Gy);
        if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && warRect.contains(Mx, My))
        warrior.move(0,-16);
};

In game loop
gameWindow.draw(warrior.warrior);
warrior.moveWar(warPos[0], warPos[1],
                                warPos[2], warPos[3],
                                mPosX, mPosY);
 

All directories and libraries are properly included where relevant. If I'm not providing enough information please let me know. I'm new to a lot of this; I'm using SFML for my second c++ course class project and so far it's helping me tremendously with learning the language, but I stumble at times with likely simple problems like these.
Title: Re: Can't Send Mouse/Rectangle Coordinates to Function
Post by: Laurent on February 23, 2013, 09:32:17 am
Quote
If I'm not providing enough information please let me know
The error message and where it happens, maybe? "it won't accept the coordinates" doesn't really mean anything for us ;)