SFML community forums
Help => General => Topic started by: nullGrind on February 01, 2010, 01:48:30 pm
-
Hello everyone!
Right now im programming on a little spaceshooter. Every time the player shoots a sprite should be generated from the same image. But my compiler keeps telling me that: main.cpp:166: error: expected primary-expression before "Shot"
Here is part of the code:
sf::Image IShot;
if (!IShot.LoadFromFile("Shot.png")) {
// Error...
}
std::vector<sf::Sprite> ShotVector;
Gameloop:
// SHOOTING
shotTimer++;
if (Game.GetInput().IsKeyDown(sf::Key::N) && shotTimer > 60) {
shotTimer = 0;
shot = true;
}
if (shot) {
shot = false;
sf::Sprite Shot;
Shot.SetImage(IRocketP1);
Shot.SetColor(sf::Color(255, 255, 255, 255));
Shot.SetPosition(350.f, 600.f);
Shot.SetCenter(Shot.GetSize().x / 2, Shot.GetSize().y / 2);
ShotVector.push_back(Shot); <--- LINE 166
}
int i = 0;
for (i = 0; i < ShotVector.size(); i++) {
Game.Draw(ShotVector[i]);
}
-
Which line is the 166 in your code?
-
its
ShotVector.push_back(Shot);
also updated my original post with a marker marking line 166[/quote]
-
Everything looks ok. Can you show a complete and minimal example that reproduces this error?
-
OMG
i was really stupid. Here is the Problem:
Shot.SetImage(IRocketP1);
I used the image for my rocket but not the image for my shot.
After fixing that the code just goes fine.
Thanks anyway Laurent![/code]