Yep so, I have a base class called 'Entity' which inherits from sf::Drawable.
I have set up 'EnemyEntity' class pretty similar to the way I set up a 'Bullet' class which are also derived from Entity however in this case the functionality is completely different.
I set up the texture of the enemies in the handler. I have a 'Texturehandler' class which I can add and get textures. In the enemies class I have function that takes in a reference to a texture and the goes through the vector and adds them accordingly to each object.
Some code below to help explain better.
I tried this code below, this works and the enemies are drawn on the screen at random positions. So I am not sure what is causing them not to be drawn from the code shown in an earlier post.
m_vEnemies[i]->getEntitySprite().setPosition(rand() % m_screenWidth, rand() % m_screenHeight);
EnemyEntity::EnemyEntity()
:Entity()
, m_speed(0.1)
, m_fireRate(0.1)
{
setEntityType(eEnemy);
getEntitySprite().setScale(0.1f, 0.1f);
setEntityActive(true);
}
void EnemyHandler::setEnemyTexture(sf::Texture& enemyTexture)
{
for (m_it = m_vEnemies.begin(); m_it != m_vEnemies.end(); m_it++)
{
EnemyEntity* pEnemy = *m_it;
pEnemy->setEntityTexture(enemyTexture);
}
}
//Base class draw function I have used in all of my other derived classes which works fine.
void Entity::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
target.draw(m_entitySprite, states);
}