SFML community forums
Help => Graphics => Topic started 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:
sf::FloatRect Restraint[2];
Restraint[0](Left, Top, Width, Height);
my compiler complains:
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
-
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.
-
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):
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.
-
sf::FloatRect Restraint[2];
Restraint[0](Left, Top, Width, Height);
This should be changed to:
sf::FloatRect Restraint[2];
Restraint[0] = sf::FloatRect(Left, Top, Width, Height);
You can't call the constructor after initialization.
-
Hmm...it still doesn't work when I do that...
sf::FloatRect Restraint[2];
Restraint[0] = sf::FloatRect(Left, Top, Width, Height);
error: expected constructor, destructor, or type conversion before ‘=’ token|
-
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).
-
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.
-
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!
-
That worked perfectly. Thanks for your help!