I have some problem with my weapon class to fire when it's costructed.
This is what i made in Weapon constructor:
Weapon::Weapon(std::string n, const int rate, const int speed):bullets("data/bullets/"+n+"bullet.png")
{
name=n;
fireRate=rate;
bullets.setSpeed(speed);
buffer.loadFromFile("data/sounds/weapons/"+n+".wav"); //SF BUFFER
weaponSound.setBuffer(buffer); // SF SOUND
weaponSound.play();
}
If i made this in my main:
Weapon test("M60",80,1500);
It plays the sound well!
Now, i tested a little weapon vector initializer, so this is what i made:
bool loadWeaponList(std::vector<Weapon> &weaponVector){
std::string tempName;
int tempRate, tempSpeed;
std::ifstream weaponFile("data/weapons/weaponlist.txt", std::ios::in);
if (!weaponFile){
std::cerr << "Weapon List File Error!"<<std::endl;
return false;
}
while(!weaponFile.eof()){
weaponFile >> tempName >> tempRate >> tempSpeed;
weaponVector.push_back(Weapon(tempName,tempRate,tempSpeed));
}
return true;
}
The function wroks for bullets and fire, but seems sound doesn't want to start! What can be the error?