Slick Forums

Discuss the Slick 2D Library
It is currently Sun Nov 19, 2017 3:00 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Mar 10, 2012 9:28 am 
As of note, the code only implements one HashMap, which is in StateBasedGame, and nothing is stored in it by default, so it creates less overhead than if Tiled support is in Slick but you don't use it. The advantage of this implementation is that we don't have to change any GameState interface methods (init, enter etc.) so it won't break any code. If anyone could provide a better example, go ahead, IMO this works.

Also, I'm not sure how everyone else does it, but it's pretty annoying using a global singleton, and I would much prefer being able to access my globals via an in built class.


Top
  
 
PostPosted: Sat Mar 10, 2012 10:00 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
I also think that there are way too many individual solutions to implement a specific one into Slick.

Please let's revert this.

And again, Liam, you're adding code that was not even talked about. Anywhere. This is not good practice.

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 3:43 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
liamzebedee wrote:
Also, I'm not sure how everyone else does it, but it's pretty annoying using a global singleton, and I would much prefer being able to access my globals via an in built class.

If you really want this feature in your games just do this:
Code:
public abstract class MyStateBasedGame extends StateBasedGame {
    protected HashMap<Object, Object> userData = new HashMap<Object, Object>();

    public MyStateBasedGame(String str) {
        super(str);
    }

    public void putUserData(Object k, Object v) { userData.put(k, v); }

    public Object getUserData(Object k) { userData.get(k); }
}


But like I said, it's bad practice. Better to pass an interface to the constructor IMO, or extend BasicGameState and StateBasedGame to handle things yourself.


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 5:08 pm 
Offline
Oldbie
User avatar

Joined: Thu Jan 13, 2011 4:42 pm
Posts: 349
I thought that having an inter-state system might be a good idea, but after reading this thread, I'm not so sure... In fact, you're probably right. The implementation of data exchange between states should be implemented by the user.

_________________
"Artificial intelligence will never be a match for human stupidity" - "Jamos Kennedynos"


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
Powered by phpBB® Forum Software © phpBB Group