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

Author Topic: One sprite, various objects, am I doing it wrong?  (Read 3227 times)

0 Members and 1 Guest are viewing this topic.

lap1994

  • Newbie
  • *
  • Posts: 11
    • MSN Messenger - lap.1994@hotmail.com
    • View Profile
One sprite, various objects, am I doing it wrong?
« 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 :(
Code: [Select]

    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]);
            }
        }
    }
Practice makes perfect.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
One sprite, various objects, am I doing it wrong?
« Reply #1 on: November 08, 2009, 08:57:32 pm »
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:
Code: [Select]
for(int i...) {
    sprite.SetPosition(stars[i].x, stars[i].y);
    sprite.SetRotation(...);
    wnd.Draw(sprite);
}

lap1994

  • Newbie
  • *
  • Posts: 11
    • MSN Messenger - lap.1994@hotmail.com
    • View Profile
One sprite, various objects, am I doing it wrong?
« Reply #2 on: November 08, 2009, 09:10:02 pm »
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
Practice makes perfect.

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
One sprite, various objects, am I doing it wrong?
« Reply #3 on: November 09, 2009, 01:30:10 am »
You probably want all the stars to use the same image. So, 1000 sprites, 1 image.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
One sprite, various objects, am I doing it wrong?
« Reply #4 on: November 09, 2009, 07:00:57 am »
You are doing right. Why don't you test your code?
:-)

 

anything