SFML community forums

Help => Graphics => Topic started by: TechRogue on October 25, 2010, 12:25:45 am

Title: sf::Rect array (Solved)
Post by: TechRogue on October 25, 2010, 12:25:45 am
I'm trying to use a for loop to check a Vector for an sf::FloatRect that contains a given coordinate set. However, when I do this:

Code: [Select]

sf::FloatRect Restraint[2];
Restraint[0](Left, Top, Width, Height);


my compiler complains:
Quote

error: expected constructor, destructor, or type conversion before ‘(’ token



Is this a mistake I'm making, or a bug in the library? Any insight would be appreciated.


SFML: 1.5
OS: Linux
Compiler: g++
IDE: Code::Blocks
Title: sf::Rect array (Solved)
Post by: Nexus on October 25, 2010, 12:38:25 am
It's your mistake, this syntax is wrong. What do you exactly want to achieve?

Maybe constructing a temporary sf::FloatRect and assigning it to the array element helps you.
Title: sf::Rect array (Solved)
Post by: TechRogue on October 25, 2010, 01:01:31 am
Thanks for the quick reply. Essentially I have a vector ("Walkable") containing sf::FloatRects that make up the area that my character can move in if he's already inside the one that the mouse clicks on. This is for a point-and-click adventure game.

I'm currently trying to do this (pseudo-code):

Code: [Select]


for (int w = 0; w < Walkable.size(); w++)
{
    if Restraint[w].Contains(Mouse_Click_X, Mouse_Click_Y)
    {
        if (Restraint[w].Contains(Actor_Y, Actor_Y)
        {
            //handle movement;
            break;
        }
    }
}
       


I need to check a good amount of rects without hard-coding them all in.
Title: Re: sf::Rect array
Post by: inlinevoid on October 25, 2010, 01:48:01 am
Code: [Select]

sf::FloatRect Restraint[2];
Restraint[0](Left, Top, Width, Height);


This should be changed to:

Code: [Select]

sf::FloatRect Restraint[2];
Restraint[0] = sf::FloatRect(Left, Top, Width, Height);


You can't call the constructor after initialization.
Title: sf::Rect array (Solved)
Post by: TechRogue on October 25, 2010, 04:24:52 am
Hmm...it still doesn't work when I do that...


Code: [Select]
sf::FloatRect Restraint[2];
Restraint[0] = sf::FloatRect(Left, Top, Width, Height);


Quote
error: expected constructor, destructor, or type conversion before ‘=’ token|
Title: sf::Rect array (Solved)
Post by: inlinevoid on October 25, 2010, 05:54:58 am
It should work fine...  It may be a bug with 1.5 though.  Try upgrading to 1.6(you won't have to change anything, the naming convention stayed the same).
Title: sf::Rect array (Solved)
Post by: Relic on October 25, 2010, 05:41:55 pm
Code: [Select]
Restraint[0] = sf::FloatRect(Left, Top, Width, Height);
It seems like you are trying to make this assignment in global scope and not inside a function. Hence the error.
Title: sf::Rect array (Solved)
Post by: TechRogue on October 29, 2010, 03:08:29 pm
That's right, this is all outside main(). I don't have access to my computer with the code on it right now, but I'll try that when I get home. Thanks!
Title: sf::Rect array (Solved)
Post by: TechRogue on October 30, 2010, 07:52:52 pm
That worked perfectly. Thanks for your help!