Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Resource Loader / Loading Screen  (Read 3640 times)
0 Members and 1 Guest are viewing this topic.
Offline Raildex

Senior Newbie





« Posted 2013-11-23 16:43:59 »

Hey there!
I want to make a Loading Screen( a progress bar painted with Java2D)

Painting the ProgressBar is no problem.
I'm more confused how to load the Resources dynamically.

My game is seperated by Scenes and the Game should be like this:
  • Loading
  • Title Screen
  • Loading
  • Level1
  • Loading
  • Level2
and so on. Since Title and every Level uses different Fields and Images and Music and Sounds to load, I have no Idea how to start a "SceneLoader".
I have no Idea how to "detect" what has to be loaded because for example Level 1 uses 2 Backgrounds, while Level 2 uses 4 Backgrounds etc. Clueless
Offline opiop65

JGO Kernel


Medals: 159
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-11-23 17:58:44 »

Well, for every level you have, you'll need to specify in the constructor which backgrounds/sounds/anything you need. What exactly are you having trouble with? You need to actually tell the level what resources you need.

Offline Sethir

Senior Newbie


Exp: 3 years



« Reply #2 - Posted 2013-11-23 18:35:29 »

I think the problem is, how to tell the loading screen that every resource is loaded. Or is it how to load these?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Slyth2727
« Reply #3 - Posted 2013-11-23 19:00:58 »

Well from a structure standpoint I suggest this:
Have the object of your LoaderClass in your Main or Game or whatever you call it class. When you first start the game switch the game state to "loading" (Just use enums. Even a small bit gamestate management code makes doing that kind of stuff a lot more organized.) and create the window for the progress bar. Then, set your variables, eg

1  
Image player = new ImageIcon("player.png").getImage();


and then after that add a bit to the number that defines how far the loading bar has progressed.
To make this more dynamic, what I usually like to do is keep and my images all in an array, or sets of arrays.
1  
2  
3  
Image[] weapons;
Image[] players;
Image[] mobs;

This way it makes it nice and easy to load from tile sets.
Also, you can make your progress bar progress based on the loading of these easily, which is really the whole point.
1  
2  
3  
4  
5  
BufferedImage weaponTileset = {Load the tileset into BI};
for(Image img : weapons){
    img = {If each tile is, say, 10x10 then progress 10 pixels down the BI and load this image into a 10x10 piece from that point.}
    progressBar.add(1);
}


Of course you probably wouldn't add one to the progress bar. Just play around with some math and get it to add to the progress bar based on how many things you have to load.

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline Raildex

Senior Newbie





« Reply #4 - Posted 2013-11-23 19:27:45 »

I implemented a File e.g. into my TitleFolder.
It describes the TitleScreen:
how many BGs,
how many maps(only used in Levels, but for standardization) are used
The Sound Files are also stored in a separated file, the same with the Music.

For every File described in the "Description" File, the progressbar gets a "MaxValue++".
For every loaded File the Progressbar gets a "Fill++".
It now looks like this:


Thanks for your help :]
Offline Slyth2727
« Reply #5 - Posted 2013-11-23 20:50:02 »

No problem Smiley always happy to help. A medal is always appreciated if I helped you though. Wink

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline opiop65

JGO Kernel


Medals: 159
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #6 - Posted 2013-11-23 21:34:08 »

Rendering a game with ImageIcons is terrible, I strongly suggest not ever recommending using them for anything other than GUIs.

Offline Slyth2727
« Reply #7 - Posted 2013-11-23 22:41:24 »

Ah I didn't know that I'll keep it in mind. Thanks!

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline Kyperbelt

Junior Devvie


Medals: 1



« Reply #8 - Posted 2013-11-23 23:47:52 »

since i abstract all my game resources such as images and sound files i made a GameResource interface that has a load(); method and a isLoaded();

then loading resources is as easy as calling load(); and in the load method just load the resource the way you normally would and then set loaded to true;

you can just as easily make an arraylist of <GameResource> and add all your resources , then amount_loaded/total_resources(make percentage) and use that to display your loading bar.
Offline opiop65

JGO Kernel


Medals: 159
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #9 - Posted 2013-11-24 00:17:35 »

Better yet, you could use a hashmap, they're quite handy for resource loading and retrieval!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kyperbelt

Junior Devvie


Medals: 1



« Reply #10 - Posted 2013-11-24 04:18:23 »

Better yet, you could use a hashmap, they're quite handy for resource loading and retrieval!

yeah this^^

i actually do this to index all my resources in a hash map but i have a different class apart from the resource loader to do that for simplicity hehe
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (73 views)
2014-11-26 15:22:04

toopeicgaming1999 (62 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (56 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!