Skip to main content
gamedev.net
🔒 Locked

[java] Loading bar

Started by Bimble Bob 6 replies 1.2k views
Original Post
Bimble Bob
Bimble Bob
I've looked everywhere I can't seem to find any tutorials on making a loading bar in Java to show how much of the media has been loaded etc. Could anyone point me in the right direction? I'm sure it has something to do with MediaTrackers but whenever I've tried something it's failed.
It's not a bug... it's a feature!
Bimble Bob
Bimble Bob
Is there a way without using Swing?
It's not a bug... it's a feature!
e-u-l-o-g-y
e-u-l-o-g-y
A progress bar is basically just a rectangle which is gradually filled so

DrawRectangle(0, top, (width * progress) / maxProgress, height, color);

should do the trick. This is, as you can see, not java specific. You said you didn't want swing so I guess you're drawing the gui parts yourself?
my-eulogy - A blog about coding and gfxsdgi - Semi-Daily Game IdeaChunkyHacker - Viewer for Relic chunky formats (used in DOW)
Bimble Bob
Bimble Bob
Yes. I know how to draw the rectangle that's fine. It's just how to tell whether an image has loaded and increasing it without the whole Applet freezing that's the trouble. I wanted to get a more personal feel with my GUI so I am writing those parts myself. An example of the sort of thing I would like is like the one in RuneScape (Which I happen to be playing at the time :P)
It's not a bug... it's a feature!
CaptainJester
CaptainJester
I think he updates based on each image loaded, not on how much of an image is loaded.

If that is what you want, then just use MediaTracker and a separate id for each image.

MediaTracker mt = new MediaTracker(this);for(int i=0;i<numImages;i++) {  image = getImage("somfile.jpg");  mt.addImage(image, i);}for(int i=0;i<numImages;i++) {  while(!mt.checkID(i)) {    try {      //required to keep this thread from locking others      Thread.sleep(20);    }    catch(InterruptedException e) {}  }  //updateProgress here}


If you want to use ImageIO instead of the old way:
for(int i=0;i<numImages;i++) {  image = ImageIO.read("somefile");  //updateProgress here}


Since ImageIO blocks until the image is loaded, you don't need MediaTracker.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Bimble Bob
Bimble Bob
Thank you. I will incorporate this into my Sprite class. I've never used ImageIO before it seems to be a lot simpler...
It's not a bug... it's a feature!
Son of Cain
Son of Cain
Quote:
Original post by Dom_152
Thank you. I will incorporate this into my Sprite class.


On your Sprite class?!? Don't you think this responsibility belongs to another class? (i.e a GameState? =)

a.k.a javabeats at yahoo.ca

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.