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

Author Topic: Implementation of a progressive drawing method  (Read 1784 times)

0 Members and 1 Guest are viewing this topic.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Implementation of a progressive drawing method
« on: October 05, 2012, 02:08:02 am »
For my game I need to implement a method that draws some sprites that appear progressively. It's a variation of the draw that draws sprites contained in a std::vector according to an offset of time I give the class. Once it draws one of the sprites that sprite will always be drawn and the next one will be pondered whether it will be drawn or not (depending on time). My current method does that partially, it does do the waiting and once something was drawn it will keep on being drawn. However the time is not exact and the drawing order isn't sequential.

Here's the code:

void BulletPlacer::drawOnce(sf::RenderTarget& target)
        {
            for (unsigned i = 0; i < UseIndex; ++i)
            {   if ( ( Time.getElapsedTime() >= Tick ) || Checker[i])
                {
                    target.draw(ShotVec[i]);

                    if(!Checker[i])
                    { Checker[i] = true; }

                    if (Time.getElapsedTime() >= Tick)
                    { Time.restart(); }
                }
            }
        }

The time needs to be exact, if Tick is 0.1 seconds then it has to draw the sprites each 0.1 secs and it is supposed not  to be able to draw ShotVec[5] before ShotVec[0] to give an example. I'm out of ideas, so I come here for guidance.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Implementation of a progressive drawing method
« Reply #1 on: October 05, 2012, 07:20:39 pm »
I think I found out what I needed to actually make it possible, this method due to it's nature of working under a different time than the window does needs to work in a different thread, that draws everything in order while the main thread waits until everything was drawn once, then it goes back to normal functioning.

However I only have conceptual knowledge of threads, I have never truly worked with them before, so I'll post doubts for them here.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 878
    • View Profile
Re: Implementation of a progressive drawing method
« Reply #2 on: October 06, 2012, 04:01:42 pm »
It's far easier and can be done in a single thread as well. You just need some variable to save the passed time (which then determines how many sprites to draw):
Code: [Select]
int framecount = 0;
//...

++framecount; // only increase once you have to "unlock" the next sprite

for(int i = 0; i < framecount; ++i)
    target.draw(ShotVec[i]);

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Implementation of a progressive drawing method
« Reply #3 on: October 06, 2012, 04:11:21 pm »
I haven't been in the forum in a while and found out the same answer on my own. While it doesn't give me exact time control (which I wanted, but I noticed it was very unpractical halfway) it will be progressive so it does give the effect I want. At least I got to know a bit more about threads which I will be using once I start with collisions.

Thanks for the answer anyway, I had been stuck for about 4 days in this and it was actually making this thread that made me review the code over and over till I came with it on my own.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!