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

Author Topic: sf::Rect array (Solved)  (Read 4345 times)

0 Members and 1 Guest are viewing this topic.

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
sf::Rect array (Solved)
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Rect array (Solved)
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
sf::Rect array (Solved)
« Reply #2 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.

inlinevoid

  • Newbie
  • *
  • Posts: 49
    • MSN Messenger - inlinevoidmain@gmail.com
    • AOL Instant Messenger - inlinevoid
    • View Profile
    • Email
Re: sf::Rect array
« Reply #3 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.

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
sf::Rect array (Solved)
« Reply #4 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|

inlinevoid

  • Newbie
  • *
  • Posts: 49
    • MSN Messenger - inlinevoidmain@gmail.com
    • AOL Instant Messenger - inlinevoid
    • View Profile
    • Email
sf::Rect array (Solved)
« Reply #5 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).

Relic

  • Newbie
  • *
  • Posts: 43
    • View Profile
sf::Rect array (Solved)
« Reply #6 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.

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
sf::Rect array (Solved)
« Reply #7 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!

TechRogue

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
sf::Rect array (Solved)
« Reply #8 on: October 30, 2010, 07:52:52 pm »
That worked perfectly. Thanks for your help!