for (int i = 0; i < enemy1M.getEnemies().size(); i++)
{
if (enemy1M.getEnemies()[i].isAlive()) // check if alive first
{
// call the slow enemies function if they collide
player.collisionResponse();
enemy1M.getEnemies()[i].collisionResponse();
//enemy1M.getEnemies()[i].setPosition(850, 850); <-- this does not work either
}
}
enemy1M.getEnemies()[i].setPosition(850, 850);
enemy1M.getEnemies()[i].collisionResponse();
// inside the enemy 1 manager constructor
for (int i = 0; i < 6; i++)
{
enemies.push_back(Enemy1());
enemies[i].setAlive(false);
enemies[i].setTexture(&texture);
enemies[i].setSize(sf::Vector2f(50, 50));
}
// from the enemy 1 manager .cpp
std::vector<Enemy1> Enemy1Manager::getEnemies()
{
return enemies;
}
How do you know? What does it do? Why is that different from what you expect it to do?
I suppose, then, this transforms my question into:
what is an Enemy1 and what is in its setPosition method?
Enemy1::Enemy1()
{
setSize(sf::Vector2f(50, 50));
position.x = 800;
position.y = 800;
setPosition(position);
scale = 10.f;
gravity = -5.0f * scale;
falling = true;
velocity.y = -100;
} // essentially making it travel upwards (all enemies are being being moved this way to give the illusion the player is falling
void Enemy1::update(float dt)
{
// this is always applying negative gravity to the enemy
if (falling)
{
velocity.y += (gravity)* dt;
move(velocity * dt);
}
updateAABB(); // updating AABB collision
}
'It not working' seems to be that it is not being moved with setPosition() but is being moved with collisionResponse(). Is that correct?
void Enemy1::collisionResponse()
{
position.y = 850;
setPosition(position);
}
Does this mean I was incorrect or that it is not being moved?Quote'It not working' seems to be that it is not being moved with setPosition() but is being moved with collisionResponse(). Is that correct?Unfortunately not.
As for setPosition();Only if the class inherits from sf::Transformable.
As far as I was aware this was from #include <SFML/Graphics.hpp>?
Since you haven't shown what the internal value position actually does, I presume that this would be the internal representation of its position. This isn't being updated when you just set the position; it is being updated when you use collision response.As for setPosition();Only if the class inherits from sf::Transformable.
As far as I was aware this was from #include <SFML/Graphics.hpp>?
position.x = xxx;
position.y = xxx;
setPosition(position);
This function returns a copy of the enemy array, not the original one. Therefore, any modification to what is returned won't impact the actual array of enemies.std::vector<Enemy1> Enemy1Manager::getEnemies()
QuoteThis function returns a copy of the enemy array, not the original one. Therefore, any modification to what is returned won't impact the actual array of enemies.std::vector<Enemy1> Enemy1Manager::getEnemies()