Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 11:46 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Feb 28, 2012 12:55 pm 
Offline

Joined: Tue Feb 21, 2012 3:46 pm
Posts: 26
Hello!

I want to show something useful while loading the needed game resources.

Are there some best practices, how I can achieve this...
With or without using Threads?

best regards
Matthias


Top
 Profile  
 
PostPosted: Wed Feb 29, 2012 9:29 am 
Offline
User avatar

Joined: Sat Jan 14, 2012 1:05 pm
Posts: 28
Location: Leipzig, Germany
At the moment I'm trying to implement a new ressource manager in my game that also has the ability to render a progressbar (or a load image). It needs no multithreading and just relies on you calling a load() method until all ressources are loaded.
The way I want it to do is something like this:
  • at game init, add all required ressources to the ressourcemanager:
    Code:
    rMan.addRessourceLocation("gfx/spritesheet.png", RessourceType.SpriteSheet, false);
    rMan.addRessourceLocation("gfx/character1.png", RessourceType.Image, false);
    ...

    This adds the ressource locations to an Arraylist. It doesn't create the actual objects hence the false as 3rd parameter.
    Specifying true as 3rd param would create the ressource upon adding.
  • Then I'll have 2 methods: loadAll() which creates the objects (Images, Animations, etc) for all ressourceLocations and loadOnce() which only creates the object for the next ressource in the arraylist
  • getting the size of the arraylist and using loadOnce multiple times in your load screen you would be able to display a progress bar or a logo while the ressources are loaded.

    Code:
    //GameState: loadScreen
    int itemsLoaded = 0;
    int numItems = -1;

    init(){
      numItems = rMan.getNumberOfRessources();
    }
    render(){
    g.DrawString("percent loaded" + (itemsLoaded*100/numItems), 100,100);
    }

    update(){
    if(itemsLoaded < numItems)
       rMan.loadOnce(); //load one ressource from the ressource list
    else
      game.enterState(STATE.MAINMENU);
    }

Does this make any sense?
Haven't implemented it yet but that's the way I planned to approach the problem.

_________________
team red


Top
 Profile  
 
PostPosted: Wed Feb 29, 2012 9:42 am 
Offline

Joined: Tue Feb 21, 2012 3:46 pm
Posts: 26
I found this!

viewtopic.php?f=3&t=3145&hilit=thread+load


Top
 Profile  
 
PostPosted: Wed Feb 29, 2012 11:02 am 
Offline
User avatar

Joined: Mon Feb 27, 2012 11:21 pm
Posts: 24
Location: Spain
Could you post what you finally did or some tips? I've read the link but I'm having troubles to implement it :S

_________________
Sorry for my English, trying to improve!


Top
 Profile  
 
PostPosted: Wed Feb 29, 2012 11:34 am 
Offline

Joined: Tue Feb 21, 2012 3:46 pm
Posts: 26
Maybe I can post my solution today, if I have enough time to work on it.!


Top
 Profile  
 
PostPosted: Wed Feb 29, 2012 1:59 pm 
Offline
User avatar

Joined: Mon Feb 27, 2012 11:21 pm
Posts: 24
Location: Spain
After trying some things i got something very simple that works following the last post on the topic you linked.

On the main class, add and enter an "Init State"

In my case:
Code:
this.addState(new InitState(INITSTATE));
this.enterState(INITSTATE);

On the main class initStateList() method just init that state:
Code:
this.getState(INITSTATE).init(gameContainer, this);

And inside "Init State" I render an image on render() and load the rest of states/resources on the update() method:
Code:
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
       
        sbg.addState(new MainMenuState(Tankz.MAINMENUSTATE));
        sbg.addState(new GameplayState(Tankz.GAMEPLAYSTATE));
        sbg.addState(new GameOverState(Tankz.GAMEOVERSTATE));
       

        sbg.getState(Tankz.MAINMENUSTATE).init(gc, sbg);
        sbg.getState(Tankz.GAMEPLAYSTATE).init(gc, sbg);
        sbg.getState(Tankz.GAMEOVERSTATE).init(gc, sbg);
       
       sbg.enterState(Tankz.MAINMENUSTATE);
    }

Like I said it's really simple and it just shows an image while loading resources, but given I don't even have a Resource Manager or anything to load resources it's fine for me, probably you can work from here to make InitState to add useful information, I don't know...

_________________
Sorry for my English, trying to improve!


Top
 Profile  
 
PostPosted: Wed Feb 29, 2012 6:09 pm 
Offline

Joined: Tue Feb 21, 2012 3:46 pm
Posts: 26
Yes I already started implementing it the same way :)

Really simple and very helpful !


Top
 Profile  
 
PostPosted: Sun Apr 01, 2012 11:55 am 
Offline
User avatar

Joined: Mon Mar 26, 2012 1:51 am
Posts: 9
thanks for the tip..this helped me a lot :wink:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group