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

Author Topic: sf::Shape in array  (Read 3249 times)

0 Members and 1 Guest are viewing this topic.

Luinechor

  • Guest
sf::Shape in array
« on: December 11, 2009, 06:55:39 pm »
Hello,

I'm trying to draw a background with like > 100 Stars. The stars are simple 1px-rectangles, which I store in an array.

Code: [Select]
sf::Shape Stars[100];

I initialize all the Shapes at start and calculate random positions, which works fine - also the drawing works fine.

I want to move the Shapes along the y-axis, so they move down. If they are out of screen I want to reset the y-position to 0.

The function looks like:
Code: [Select]
for (int i = 0; i < 100; i++) {
if (Stars[i].GetPosition().y <= pWindow->GetHeight()) {
Stars[i].Move(0, 5);
} else {
Stars[i].SetPosition(Stars[i].GetPosition().x, 0.f);
}
}


The problem is:
Stars move down. No star's y-position will be set to 0.
Only when the 'first' (the star, which has the lowest y-value) is at the end of the screen, all of the star's y-position will be set to the standard value (the calculaled random positions, because the stars-composition looks like at the beginning of the application).

I'm confused. All the asteroids and shots work fine. I'm using sf::Sprite for them and vectors to store them.

Greetigs,
Luinechor

Update:
It works now!

Got it working with the help of this thread: http://sfml-dev.org/forum/viewtopic.php?t=679&highlight=shape

 

anything