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

Author Topic: Help with collision!  (Read 1866 times)

0 Members and 1 Guest are viewing this topic.

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Help with collision!
« on: May 30, 2011, 09:27:37 pm »
I got the linkage to work, but got a little problem with the collision itself.

Code: [Select]
       if (Collision::BoundingBoxTest(const sf::Shape& Main, const sf::Shape& Ground)){
            gravity *= -1;
        }


Gave me:

Code: [Select]
"error: expected primary-expression before 'const'"

I'm not that good at using references, seeing that there's one there.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Help with collision!
« Reply #1 on: May 30, 2011, 10:04:38 pm »
You're mixing a function declaration with an actual call.

Declaration:
Code: [Select]
bool Collision::BoundingBoxTest(const sf::Shape& Main, const sf::Shape& Ground);

Call:
Code: [Select]
Collision::BoundingBoxTest( main_shape, ground_shape );

Whereas main_shape and ground_shape are both sf::Shape objects that get automagically referenced (due to the function's signature).

Maybe start with a beginner's C++ book, it's rather basic knowledge.

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Help with collision!
« Reply #2 on: May 30, 2011, 10:44:01 pm »
I already tried that earlier and got this:

Code: [Select]
error: no matching function for call to 'Collision::BoundingBoxTest(sf::Shape&, sf::Shape&)'|

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
Help with collision!
« Reply #3 on: May 31, 2011, 12:18:58 am »
I just looked at the page for sf::Collision. It accepts two references to sf::Sprite, not two references to sf::Shape, hence the error - the compiler tells you that there is
Code: [Select]
no matching function for call to 'Collision::BoundingBoxTest(sf::Shape&, sf::Shape&)
because there is no such function.

See here: http://www.sfml-dev.org/wiki/en/sources/simple_collision_detection

Your other code is not solving the problem, merely masking it with a more fundamental problem.

EDIT:
Quote
Maybe start with a beginner's C++ book, it's rather basic knowledge.

If you don't want to buy a book:
http://www.cplusplus.com/doc/tutorial/

 

anything