hey guys...now I know how vertex array works..
so I have a game that has an enemy that multiplies by 2 when you killed it...
so considering I use loop to draw it...it gets too slow eventually
now.. I have this class
class Zombie
{
private :
sf::RectangleShape Rect;
const float speed;
int health;
public :
Zombie(const sf::RenderWindow& window, float speedVal, int healthVal) :
speed(speedVal),
health(healthVal)
{
std::srand(time(0));
Rect.setSize(sf::Vector2f(37, 37));
Rect.setOrigin(Rect.getSize().x / 2, Rect.getSize().y / 2);
sf::Vector2f position;
rand();
position.x = rand() % window.getSize().x;
rand();
position.y = rand() % window.getSize().y;
Rect.setPosition(position);
Rect.setFillColor(sf::Color(0, 200, 0));
}
void move(User& user)
{
if (Rect.getPosition().x < user.getPosition().x)
{
Rect.move(speed, 0);
}
else if (Rect.getPosition().x > user.getPosition().x)
{
Rect.move(-(speed), 0);
}
if (Rect.getPosition().y < user.getPosition().y)
{
Rect.move(0, speed);
}
else if (Rect.getPosition().y > user.getPosition().y)
{
Rect.move(0, -(speed));
}
sf::Vector2f difference;
difference.x = user.getPosition().x - Rect.getPosition().x;
difference.y = user.getPosition().y - Rect.getPosition().y;
float face = std::atan2(difference.y, difference.x);
float degrees = face * pi / 180;
Rect.setRotation(degrees);
}
void reInit(const sf::RenderWindow& window)
{
srand(time(0));
rand();
sf::Vector2f position;
position.x = rand() % window.getSize().x;
rand();
position.y = rand() % window.getSize().y;
Rect.setPosition(position);
health = 50;
}
void decHealth(int val)
{
health -= val;
}
const int& getHealth() const
{
return health;
}
const sf::Shape& getShape() const
{
return Rect;
}
bool hit(User& user)
{
if (Rect.getGlobalBounds().intersects(user.getGlobalBounds())) return true;
return false;
}
};
and I have this code
std::vector<Zombie> zombie;
considering the fact that when it gets too big it becomes slow...
how do I compress it to vertex array rather how do I transform only a member of the vertex array
well...I tried to do that...I failed instead....because now they are not drawn on the screen
btw..here's the piece of code to do what you said
if (drawZombie.getVertexCount() < zombie.size() * 4)
{
for (int i = 0; i < zombie.at(zombie.size() - 1).getShape().getPointCount(); ++i)
{
drawZombie.append(zombie.at(zombie.size() - 1).getShape().getPoint(i));
}
}
for (int i = 0; i < zombie.size(); ++i)
{
for (int j = 0; j < zombie.at(i).getShape().getPointCount(); ++j)
{
drawZombie[(((i + 1) * 4) - 1) - (3 - j)].position = zombie.at(i).getShape().getPoint(j);
}
}
for (int i = 0; i < drawZombie.getVertexCount(); ++i)
{
drawZombie[i].color = sf::Color::Green;
}
and drawZombie's primitive type is of quads