Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 2:02 am

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Tue Jul 10, 2012 8:25 pm 
Offline

Joined: Tue Jul 10, 2012 8:15 pm
Posts: 2
First, let me just say this is a really amazing tool and I'm so pleased to have discovered it as it does so many useful things.
However I'm having a few problems with my game, and I'm wondering if it's because I'm either missing something very obvious or I'm doing it wrong in the first place.

I'm writing a game that uses multiple states, with each 'level' using different maps and sprites and different mechanics I decided that it would be a good idea to have each level be in a different state and that when I moved between them, just pass across variables such as player/party/inventory information. However this doesn't seem to be possible and I'm wondering if there is a better way to do things. I've already tried using singletons but I can't seem to find a way of getting them to do what I want. Should I try to put everything in a single state or is there another way around this.

Hope you can help.

HistoryMaker118
"Embrace the Inner Geek"


Top
 Profile  
 
PostPosted: Wed Jul 11, 2012 11:47 am 
Offline
User avatar

Joined: Wed Jun 20, 2012 10:33 pm
Posts: 35
Location: Doncaster, South Yorkshire
Just put all of the stats and inventory etc. into one class and then call them with an object.


Top
 Profile  
 
PostPosted: Thu Jul 12, 2012 10:57 pm 
Offline

Joined: Tue Jul 10, 2012 8:15 pm
Posts: 2
Thank you for your suggestion. Have now figured out how to solve at least one of my problems. It was just me being stupid and trying to over complicate things.
:D
Now just to figure out why the text input field isn't working for one of my screens...

HistoryMaker118
"Embrace the Inner Geek"


Top
 Profile  
 
PostPosted: Fri Jul 13, 2012 4:52 pm 
Offline

Joined: Sat Jun 23, 2012 4:14 pm
Posts: 74
Location: Germany
I wonder if my question is related: How can I pass arguments when entering another state. Let's say, I'm in the main menu and choose savegame nr. 2, how can GameplayState know about it? I don't want to implement a God Object or similar anti-patterns.


Top
 Profile  
 
PostPosted: Sun Jul 15, 2012 7:03 am 
Offline

Joined: Sun Jul 08, 2012 10:33 am
Posts: 27
search for 'singleton class' in the forums. i found my answer there :) this question came up a lot


Top
 Profile  
 
PostPosted: Thu Jul 19, 2012 11:41 am 
Offline

Joined: Sat Jun 23, 2012 4:14 pm
Posts: 74
Location: Germany
Khorne wrote:
search for 'singleton class' in the forums. i found my answer there :) this question came up a lot

Thanks, but I'm not sure if this is the best solution. The singleton pattern is also often seen as an anti-pattern and if not it might develop into one.


In this thread davedes wrote:
davedes wrote:
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.

Can anyone give me an example for both of these?

If not.. do you know another good way to transfer data from one state to another other than implementing a singleton.

Thanks for your help! :)


Top
 Profile  
 
PostPosted: Thu Jul 26, 2012 4:25 pm 
Offline

Joined: Sat Jun 23, 2012 4:14 pm
Posts: 74
Location: Germany
Nobody? Is a globals class (singleton) really a good solution?


Top
 Profile  
 
PostPosted: Mon Jul 30, 2012 10:09 am 
Offline

Joined: Sun Jul 08, 2012 10:33 am
Posts: 27
well i guess its not but why wasting time for smth like this if u dont even have the game done :) its hard enough to make the game as it is. sugar stuff is for l8r^^


Top
 Profile  
 
PostPosted: Wed Aug 01, 2012 1:26 pm 
Offline

Joined: Sat Jun 23, 2012 4:14 pm
Posts: 74
Location: Germany
Khorne wrote:
well i guess its not but why wasting time for smth like this if u dont even have the game done :) its hard enough to make the game as it is. sugar stuff is for l8r^^


I've already made the basic part of my game, but I would like to have a clean solution for entering another game state with parameters. :)


Top
 Profile  
 
PostPosted: Mon Aug 06, 2012 1:57 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Pass an interface (e.g. GameContext) to your entity's constructors or update/render methods. The interface has "global" methods you may need like getGameDifficulty, enterMenuState, etc. Virium does this.

Or extend the classes to provide more info, and pass those instead of an interface.

If you aren't familiar with objects and interfaces, you probably aren't comfortable enough with Java to be programming a game in Slick. :)

As for singleton, just google it. There are plenty of examples on the web, and a few scattered in the forums.


Top
 Profile  
 
PostPosted: Wed Aug 08, 2012 12:51 pm 
Offline

Joined: Sat Jun 23, 2012 4:14 pm
Posts: 74
Location: Germany
davedes wrote:
If you aren't familiar with objects and interfaces, you probably aren't comfortable enough with Java to be programming a game in Slick. :)

As for singleton, just google it. There are plenty of examples on the web, and a few scattered in the forums.


Of course I'm familiar with objects, interfaces and design patterns like singleton (which is often considered an anti-pattern btw.). Indeed I was not sure about how to use interfaces in this situation to pass arguments to another gamestate.

davedes wrote:
Pass an interface (e.g. GameContext) to your entity's constructors or update/render methods. The interface has "global" methods you may need like getGameDifficulty, enterMenuState, etc. Virium does this.

Or extend the classes to provide more info, and pass those instead of an interface.

Thank you! :wink:


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 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