粒子系统:所有粒子都沿相同方向移动

问题描述 投票:1回答:1

我正在尝试创建一个粒子系统。在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);

  }

 }
c++ sfml
1个回答
0
投票
for (int it = 0; it < pAtm; it++) {
        particleVector.push_back(Particle(size, sides, velocity, pAtm));
}
© www.soinside.com 2019 - 2024. All rights reserved.