The rocket doesn't need to know about it's particles, that code goes in the Game/Level update function. A very simplified example:
[source lang="cpp"]void update(){ rocket.move(); if(rand() % 5 < 1) //create a particle on 20% of the frames particles.push_back(new Particle( rocket.getX(), rocket.getY() ) ); //or if you want smart pointers instead: particles.push_back(std::make_shared< Particle >(rocket.getX(), rocket.getY())); for(auto particle : particles) { if( particle.isDead() ) //erase particle code here else particle.update(); }}[/source]
Show differencesHistory of post edits
#3sednihp
Posted 13 October 2012 - 07:57 AM
The rocket doesn't need to know about it's particles, that code goes in the Game/Level update function. A very simplified example:
[source lang="cpp"]void update(){ rocket.move(); if(rand() % 5 < 1) //create a particle on 20% of the frames particles.push_back(new Particle( rocket.getX(), rocket.getY() ) ); //or if you want smart pointers instead: particles.push_back(std::make_shared<Particle>(rocket.getX(), rocket.getY())); for(auto particle : particles) { if( particle.isDead() ) //erase particle code here else particle.update(); }}[/source]
[source lang="cpp"]void update(){ rocket.move(); if(rand() % 5 < 1) //create a particle on 20% of the frames particles.push_back(new Particle( rocket.getX(), rocket.getY() ) ); //or if you want smart pointers instead: particles.push_back(std::make_shared<Particle>(rocket.getX(), rocket.getY())); for(auto particle : particles) { if( particle.isDead() ) //erase particle code here else particle.update(); }}[/source]
#2sednihp
Posted 13 October 2012 - 07:57 AM
The rocket doesn't need to know about it's particles, that code goes in the Game/Level update function. A very simplified example:
[source lang="cpp"]void update(){ rocket.move(); if(rand() % 5 < 1) //create a particle on 20% of the frames particles.push_back(new Particle( rocket.getX(), rocket.getY() ) ); //or if you want smart pointers instead: particles.push_back(std::make_shared<Particle>(rocket.getX(), rocket.getY())); for(auto particle : particles) { if( particle.isDead() ) //erase particle code here else particle.update(); }}[/source]
[source lang="cpp"]void update(){ rocket.move(); if(rand() % 5 < 1) //create a particle on 20% of the frames particles.push_back(new Particle( rocket.getX(), rocket.getY() ) ); //or if you want smart pointers instead: particles.push_back(std::make_shared<Particle>(rocket.getX(), rocket.getY())); for(auto particle : particles) { if( particle.isDead() ) //erase particle code here else particle.update(); }}[/source]
#1sednihp
Posted 13 October 2012 - 07:57 AM
The rocket doesn't need to know about it's particles, that code goes in the Game/Level update function. A very simplified example:
[source lang="cpp"]void update(){ rocket.move(); if(rand() % 5 < 1) //create a particle on 20% of the frames particles.push_back(new Particle( rocket.getX(), rocket.getY() ) ); //or if you want smart pointers instead: particles.push_back(std::make_shared<Particle>(rocket.getX(), rocket.getY())); for(auto particle : particles) { if( particle.isDead() ) //erase particle code here else particle.update(); }}[/source]
[source lang="cpp"]void update(){ rocket.move(); if(rand() % 5 < 1) //create a particle on 20% of the frames particles.push_back(new Particle( rocket.getX(), rocket.getY() ) ); //or if you want smart pointers instead: particles.push_back(std::make_shared<Particle>(rocket.getX(), rocket.getY())); for(auto particle : particles) { if( particle.isDead() ) //erase particle code here else particle.update(); }}[/source]