Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Loading sprites into a vector  (Read 1783 times)

0 Members and 1 Guest are viewing this topic.

nullGrind

  • Newbie
  • *
  • Posts: 23
    • View Profile
Loading sprites into a vector
« 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]);
        }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Loading sprites into a vector
« Reply #1 on: February 01, 2010, 02:01:18 pm »
Which line is the 166 in your code?
Laurent Gomila - SFML developer

nullGrind

  • Newbie
  • *
  • Posts: 23
    • View Profile
Loading sprites into a vector
« Reply #2 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]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Loading sprites into a vector
« Reply #3 on: February 01, 2010, 03:16:51 pm »
Everything looks ok. Can you show a complete and minimal example that reproduces this error?
Laurent Gomila - SFML developer

nullGrind

  • Newbie
  • *
  • Posts: 23
    • View Profile
Loading sprites into a vector
« Reply #4 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]

 

anything