Hey i am doing a space shooting game.
So far i am proud of progress
I have an issue that every time i press space to a shoot a bullet the first bullet that is fired disappears .
I am using a vector of the bullet to create and move the bullets
Why does this happen and how can i fix it ;
here is my main function
int main()
{
int i=0;
Ship shipObject;
Bullet bullletObject;
vector <Bullet> bulletArsenal;
///Creates the Window
myGameGUI.create(sf::VideoMode(1000,680), "WorkingGameProject");
sf::Style::Default;
Background();///Creates the background
///calls function ship class and creates the ship
shipObject.createShip(shipTexture, shipImage);
while(myGameGUI.isOpen())
{
while(myGameGUI.pollEvent(action))
{
closeFunction();
}
///Calls function from ship class and Moves the ship
shipObject.moveShip(action, shipImage,myGameGUI);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)){
bulletArsenal.push_back(bullletObject);/// adds a new object to the vector
bulletArsenal[i].createBullet(bulletTexture,bulletImage,shipImage);/// creates a bullet of a specific object
}
bulletArsenal[i].moveBullet(bulletImage); ///move the bullet of a specific object
myGameGUI.clear();///clears screen
myGameGUI.draw(backgroundImage);///draws the background
shipObject.drawShip(myGameGUI,shipImage);///draws the ship
bulletArsenal[i].drawBullet(myGameGUI,bulletImage);///draws the bullet of a specific object
myGameGUI.display();
i++;