SFML community forums
Help => Graphics => Topic started by: lap1994 on November 08, 2009, 05:57:52 pm
-
I am new to SFML and I'm making a small shmup. I have this image of a star(its actually a white dot but whatever). Then Ive to draw each of the 1000 stars in the screen. But instead of using one sprite for each star I use sprite for every star! And I'm not sure if this is the right way :(
for(int i = 0; i < (int)cg->stars.size(); i++)
{
switch(cg->stars[i].kind)
{
case 0:
{
cg->sprites[sid_star0].SetPosition(cg->stars[i].x, cg->stars[i].y);
cg->sprites[sid_star0].SetRotation(cg->stars[i].rot);
wnd.Draw(cg->sprites[sid_star0]);
}
case 1:
{
cg->sprites[sid_star1].SetPosition(cg->stars[i].x, cg->stars[i].y);
cg->sprites[sid_star1].SetRotation(cg->stars[i].rot);
wnd.Draw(cg->sprites[sid_star1]);
}
}
}
-
I don't get it at all, but maybe you should consider using just one sprite, and changing its position and rotation every step before drawing it.
Like this:
for(int i...) {
sprite.SetPosition(stars[i].x, stars[i].y);
sprite.SetRotation(...);
wnd.Draw(sprite);
}
-
Thats what I'm doing. One sprite per image. One sprite for every object
I'm just not sure if this is the right way
-
You probably want all the stars to use the same image. So, 1000 sprites, 1 image.
-
You are doing right. Why don't you test your code?
:-)