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

Author Topic: [Solved]initial value of reference to non-const must be an lvalue  (Read 1639 times)

0 Members and 1 Guest are viewing this topic.

ecarusb

  • Newbie
  • *
  • Posts: 4
    • View Profile
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;
       
};

 
« Last Edit: August 01, 2024, 08:39:35 pm by ecarusb »

ecarusb

  • Newbie
  • *
  • Posts: 4
    • View Profile