So I am trying to make a canon that shoots bullets, the only problem that I'm having is that I don't know how to move/draw the objects sprite efficently. The commented parts are where the problem lies
Maybe I am missing something, but it seems that the above code will iterate through each item in myBullet[].
I'm not familiar with the library you are using, but no matter the method, each item will have to be dealt with one item at a time. The illusion comes when speed seemingly outputs it all at once or you are refreshing the screen from a buffer.
Can you explain what you see when you run your above program and what your expectations are?
Like I said the commented parts are where the problem lies so myBullet[i].sprite.Move(150 * App.GetFrameTime(), 0); needs to be applyed to all the objects but I cant just do
myBullet[0].sprite.Move(150 * App.GetFrameTime(), 0);
myBullet[1].sprite.Move(150 * App.GetFrameTime(), 0);
myBullet[2].sprite.Move(150 * App.GetFrameTime(), 0);
etc.. becuase they only get created once every second so from 0 - 1 this code will run and it will crash the program becuase there are no objects on those indexes yet.
same goes for App.Draw(myBullet[i].sprite);
So what I want is a bullet being created once every second and when it gets created it gets drawn and moves to the right (150 * App.GetFrameTime(), 0)
so I managed to created one every second but I'm not sure how to continue on from here. Sorry if I was unclear at first.
Actually, nevermind. I'm too busy to be on all day. Here:
1 2 3 4 5
myBullet[i].sprite.Move(150 * App.GetFrameTime(), 0); // only applies to 1 object at a time :(
App.Clear(sf::Color(255,255,255,255));
App.Draw(myBullet[i].sprite); // only applies to 1 object at a time :(
App.Display();
Now. Don't chew me out if you already fixed this, but the reason why it only applies to 1 object is because you are looping your program, not the application of moving and drawing every object.
In fact, I see one while loop. And it has nothing to do with the objects. Everything else is in an if statement, or just the while block. So, all your awesome code that makes checks, moves, and draws the bullets happens only one time. Then the while block loops back around. If you want every bullet to change at once, then you need to redraw EVERY bullet, THEN redraw the screen (which is App.Display(); in this case). But your code is very specifically drawing one bullet, updating the scree, drawing the next bullet, updating the screen, and so on.