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

Author Topic: Return sprite to collision function from inside Vector  (Read 1930 times)

0 Members and 1 Guest are viewing this topic.

Sam42

  • Newbie
  • *
  • Posts: 16
    • View Profile
Return sprite to collision function from inside Vector
« on: January 11, 2011, 06:05:06 am »
I have an Entity baseclass which the classes Player and Enemy Inherit.
Code: [Select]

class Entity
{
  public:

    virtual void Update(sf::RenderWindow &window) {};
    virtual void Draw(sf::RenderWindow &window) {};

};


Both player and enemy contain a sprite object that looks like this:
Code: [Select]

class Player : Entity
{
   public:

   sf::Sprite sprite

    void Update(sf::RenderWindow &window);
    void Draw(sf::RenderWindow &window)
}

Player and Enemy are created inside a vector which is set up like this:

Code: [Select]
class EntityManager
{
   public:
   void CollisionCheck();
   private:
   std::vector<Entity*> entityVector;
}


I'm looking to use the collision detection function from the wiki which is of this form:

Code: [Select]
bool Collision::CircleTest(const sf::Sprite& Object1, const sf::Sprite& Object2)

So I'm trying to do something like this:

Code: [Select]
void EntityManager::ColCheck()
{
   if (Collision::CircleTest(entityVector[0]->sprite, entityVector[1]->sprite))
      {
         cout << "COLLISION\n";
      }
}


This results in the following compile error: ‘class Entity’ has no member named ‘sprite’

I'm unsure how to create a dummy sprite in Entity so that I can access the player and enemy sprites using the above method. Is this possible?

I'm stumped and would greatly appreciate any help anyone can offer!

Sam42

  • Newbie
  • *
  • Posts: 16
    • View Profile
Return sprite to collision function from inside Vector
« Reply #1 on: January 11, 2011, 07:50:12 am »
Once I declared sf::Sprite sprite inside Entity rather than Player everything started working. So this is solved!