SFML community forums

Help => General => Topic started by: nullGrind on February 01, 2010, 01:48:30 pm

Title: Loading sprites into a vector
Post 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:
Code: [Select]

    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]);
        }
Title: Loading sprites into a vector
Post by: Laurent on February 01, 2010, 02:01:18 pm
Which line is the 166 in your code?
Title: Loading sprites into a vector
Post by: nullGrind on February 01, 2010, 02:03:45 pm
its
Code: [Select]
ShotVector.push_back(Shot);


also updated my original post with a marker marking line 166[/quote]
Title: Loading sprites into a vector
Post by: Laurent on February 01, 2010, 03:16:51 pm
Everything looks ok. Can you show a complete and minimal example that reproduces this error?
Title: Loading sprites into a vector
Post by: nullGrind on February 01, 2010, 03:38:15 pm
OMG
i was really stupid. Here is the Problem:
Code: [Select]

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]