Hello,
So I'm having issues understanding something and I'm not sure if this is the correct place to ask this since technically its more game code related and not SFML related but we'll see.
If you want to shoot a projectile from a character using a class called lets say projectile, the way I saw another person do it was he would whenever space was pressed, create an instance of projectile then push it back onto a vector.
I have two questions about this; firstly shouldn't you use a dynamic instance of the projectile and then delete it either when the program ends by looping through the vector, or if it goes out of screen(certain cordinate?). Secondly I can't understand how creating the instance and pushing it onto the vector works? For example the code:
for("player presses space bar")
{
projectle1.rect.setPosition(Player1.rect.getPosition()); //rect is just the hitbox and image is following it
projectleArray.push_back(projectle1);
}
This is creating a using the same instance called projectile1 over and over again? How does that even make sense? does that mean when you delete projectle1 all the projectiles are lost?
Also again should you use a dynamic version of projectle1? Or can you not do that with instances.. Kinda new to this.
Thanks