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

Author Topic: Can't Send Mouse/Rectangle Coordinates to Function  (Read 1257 times)

0 Members and 1 Guest are viewing this topic.

Bleemo

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
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.
« Last Edit: February 22, 2013, 06:52:21 pm by Bleemo »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Can't Send Mouse/Rectangle Coordinates to Function
« Reply #1 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 ;)
Laurent Gomila - SFML developer