this might be more of a C++ question rather than SFML
why does the following code work
Collider playerCollider = player.GetCollider();
platform1.GetCollider().CheckCollision(playerCollider, 0.0f);
but this doesn't
platform1.GetCollider().CheckCollision(player.GetCollider(), 0.0f);
for reference this is player.h
class Player
{
public:
Player(sf::Texture* texture, sf::Vector2u imageCount, float swtichTime, float speed);
void Update(float deltaTime);
void Draw(sf::RenderWindow& window);
sf::Vector2f GetPosition() { return body.getPosition(); }
Collider GetCollider() { return Collider(body); }
private:
sf::RectangleShape body;
Animations animation;
unsigned int row;
float speed;
bool faceRight;
float idleTime;
};
platform.h
class Platform
{
public:
Platform(sf::Texture* texture, sf::Vector2f size, sf::Vector2f Postion);
~Platform();
void Draw(sf::RenderWindow& window);
Collider GetCollider() { return Collider(body); }
private :
sf::RectangleShape body;
};
Collider.h
class Collider
{
public:
Collider(sf::RectangleShape& body);
~Collider();
void Move(float dx, float dy) { body.move(dx, dy); }
bool CheckCollision(Collider & other, float push);
sf::Vector2f GetPosition() { return body.getPosition();}
sf::Vector2f GetHalfSize() { return body.getSize() / 2.0f; }
private:
sf::RectangleShape& body;
};