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
Here is the code
Declarations.h
#ifndef DECLARATIONS_H
#define DECLARATIONS_H
class bullet
{
public:
bullet(){shoot = true;}
sf::Clock clock;
sf::Sprite sprite;
void setShoot(bool setShoot){shoot = setShoot;}
bool getShoot(){return shoot;}
private:
bool shoot;
};
#endif
Main.cpp
#include <iostream>
#include <vector>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>
#include "Declarations.h"
using namespace std;
int main ()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Bullet");
App.SetFramerateLimit(90);
sf::Image Bullet_Bill;
Bullet_Bill.LoadFromFile("Bullet_Bill.png");
int i = 0;
bullet bulletMember;
bullet myBullet[10];
vector <bullet> bulletlist;
while(App.IsOpened())
{
sf::Event Event;
while(App.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
App.Close();
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
if (bulletMember.clock.GetElapsedTime() > 1.0 && bulletMember.getShoot() == true && i <= 8)
{
cout << "Bang! " << i << endl;
i ++;
bulletlist.push_back(myBullet[i]);
myBullet[i].sprite.SetImage(Bullet_Bill);
bulletMember.setShoot(false);
}
if (bulletMember.getShoot() == false)
{
bulletMember.clock.Reset();
bulletMember.setShoot(true);
}
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();
}
}