Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 loading screen effect
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
whoareyou




PostPosted: Tue May 24, 2011 6:19 pm   Post subject: loading screen effect

I am trying to collect information about the players' names for my game while trying to have a "loading" effect going across the bottom. The problem is that, to my knowledge, I can only do one thing at a time. So what's happening with the code I have right now is that it's collecting the players' names then doing the loading stuff, but I want it to do the loading effect while I'm getting the names as well. IS that possible?

btw, this code isn't finished yet. also, CoverUp is my own method so the loading thing refreshes without clearing the console
Java:

        boolean hasLoaded = false;
        while (hasLoaded = true)
        {
            c.print ("Player 1: ");
            player1 = c.readString ();

            while (true)
            {

                c.setCursor (25, 80 - 11);

                c.print ("Loading .");
                Thread.sleep (500);


                c.setCursor (25, 80 - 11);
                c.print ("Loading ..");
                Thread.sleep (500);


                c.setCursor (25, 80 - 11);
                c.print ("Loading ...");
                Thread.sleep (500);

                CoverUp (500);

            }


        }

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue May 24, 2011 10:43 pm   Post subject: Re: loading screen effect

whoareyou @ Tue May 24, 2011 6:19 pm wrote:
The problem is that, to my knowledge, I can only do one thing at a time.

Pretty much (there's concurrency, but it's a complicated topic covered in parts in upper year University courses).

So the typical approach is to switch between two (or more) different tasks really fast. E.g.
code:

loop
   x1 += 1;
   Draw.Ball(x1,y1);
   x2 += 1;
   Draw.Ball(x2,y2);
end loop

The code still executes one line at a time. You move one ball, then you move another ball. But since the loop executes fast enough, it seems that both are moving "at the same time". The same approach applies to everything.

Naturally you can't have any blocking calls -- any functions that spend a notable amount of time doing something (this includes sleep and waiting for input). You might have to find (or build) non-blocking alternatives.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: