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 - Bleemo

Pages: [1]
1
Window / Can't Send Mouse/Rectangle Coordinates to Function
« 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.

Pages: [1]