我正在尝试创建一个粒子系统。在ParticleSystem
构造函数中,我创建具有随机颜色和速度的新粒子。当我运行代码时,所有粒子都有不同的颜色,但朝着相同的方向移动
#include "stdafx.h"
#include "ParticleSystem.h"
ParticleSystem::ParticleSystem(){}
ParticleSystem::ParticleSystem(float size, int sides, sf::Vector2f velocity,
int pAtm)
: Particle(size, sides, velocity, pAtm)
{
for (int it = 0; it < pAtm; it++) {
particleVector.push_back(Particle(size, sides, velocity, pAtm));
}
}
ParticleSystem::~ParticleSystem()
{
}
const bool& ParticleSystem::getClick() const
{
return isClick;
}
void ParticleSystem::checkForClick()
{
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
isClick = true;
}
else {
isClick = false;
}
}
void ParticleSystem::update(const float& ft)
{
checkForClick();
move(dt);
//update1(dt);
}
void ParticleSystem::render(sf::RenderTarget& target)
{
for (std::vector<Particle>::iterator it = particleVector.begin(); it != particleVector.end(); ++it) {
target.draw(shape);
}
}
for (int it = 0; it < pAtm; it++) {
particleVector.push_back(Particle(size, sides, velocity, pAtm));
}