Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Changing scenes in a game (ex; from map to battle)  (Read 1106 times)
0 Members and 1 Guest are viewing this topic.
Offline FierstArter

Junior Newbie




:3c


« Posted 2013-02-13 17:26:49 »



I've been using the fallowing enum for quite some time:

1  
public static enum Scene { Menu, Options, Map, Treasure, Battle, Pause, SetupBattle, FinishBattle, Exp, Died };


The enum is used to determine what to draw and update.

As i'm adding more and more I'm finding this solution to become quite bloated and hard to navigate. I was wondering how other people have gone about changing scenes.


Also, Hello JGO Cheesy
Offline _Scyth_

Junior Member





« Reply #1 - Posted 2013-02-13 17:35:17 »

You could have different enums for different events.

for example, enums for the battle scenes
enums for the menus
enums for the maps
etc etc

then you just need to check which enum is active.

not sure if its a great solution, but it may be achievable
Offline FierstArter

Junior Newbie




:3c


« Reply #2 - Posted 2013-02-13 17:38:46 »

That's what I'm using right now. (I should have clarified that).

It works great when there isn't much to change between. But adding more and more scenes it's become way to bloated and a pain to go through. I was wondering if anyone had a different approach to this.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline vbrain
« Reply #3 - Posted 2013-02-13 17:41:32 »

Bad advice, _Scyth_

Read on how LibGDX uses Screen classes and a central Game class:

https://code.google.com/p/libgdx-users/wiki/ScreenAndGameClasses
http://www.javacodegeeks.com/2012/05/android-game-development-with-libgdx_03.html

You have a central game class that has methods "getScreen()" and "setScreen(Screen screeen)".
You create different screen classes which implement Screen
You have you central rendering thread get the current screen using getScreen() and it draws and updates the screen.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2013-02-13 17:46:34 »

Bad advice, _Scyth_
Please don't target the person, vbrain Pointing

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline vbrain
« Reply #5 - Posted 2013-02-13 17:56:58 »

Please don't target the person, vbrain Pointing
Ok, Riven. I just needed to get the point across.
Offline FierstArter

Junior Newbie




:3c


« Reply #6 - Posted 2013-02-13 17:57:23 »

I found that libGDX while googling around looking for a solution. The only real issue I have with it is that I'm trying to stray away (for now) from using outside libraries. This "game" I'm making is more of a learning experience than anything else.



Or perhaps I'll learn how to use a library and stop being intimidated of them.
Thanks for the link, I'll definitely check it out Cheesy
Offline vbrain
« Reply #7 - Posted 2013-02-13 17:59:31 »

I found that libGDX while googling around looking for a solution. The only real issue I have with it is that I'm trying to stray away (for now) from using outside libraries. This "game" I'm making is more of a learning experience than anything else.



Or perhaps I'll learn how to use a library and stop being intimidated of them.
Thanks for the link, I'll definitely check it out Cheesy

I wasn't telling you to use libgdx. I said you should read their documentation and see how they use screens. Then you can easily make your own.
Offline ctomni231

JGO Wizard


Medals: 98
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #8 - Posted 2013-02-13 22:10:37 »

Instead of using an enum, did you ever consider just using an ArrayList (or List) to register your screens?

Just give each screen an ID (similar to you enum ID). It should be a lot less messy and you should be able to handle many screens at once.

Offline Varkas
« Reply #9 - Posted 2013-02-13 23:03:27 »

I was wondering how other people have gone about changing scenes.

Sometimes I use delegates to implement the painting. Then I just set the right painter delegate to the display panel.

Sometimes I've been using the CardLayout.

Sometimes I've been just replacing JPanels (remove old + add new ) with different content.

And I've been using flags like you ... all of them worked well in the right situation.


if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zngga
« Reply #10 - Posted 2013-02-14 00:55:28 »

No one else better known has jumped in and said it, so I will!  Emo

We program in an OOP Language (JAVA) if you don't understand what OOP means, look it up (then do some serious thinking about your choice in hobby / career) We have these great things called Classes, and they allow up to group similar data and methods into a logical structure. The answer for hard to navigate, bloated, and confusing code is almost always going to be; "Lets make another class!" /rant

For your particular scenario, I would recommend making a abstract class / interface (depends on mood this time Smiley) which is a state. I am assuming you have an update method and a render method somewhere in your big, giant, monolithic, dresser drawer of a main class. So instead of all your logic and all your rendering for the whole entire game being stuffed into these two (I hope they are separate) methods, simply have these call the current states update and render methods. When you transition from Battle to FinishBattle, simply swap out the current state.

I could take another five minuets adding code examples, but honestly I believe in your intelligence, and would hate to insult you by giving you what you can already figure out. If this is not the case simply ask Smiley

BTW: Laugh with my words, and don't take offense. I am trying to help in the cheekiest way I know how.

My code never has bugs... it just develops unexpected features!
Offline vbrain
« Reply #11 - Posted 2013-02-14 01:03:58 »

...
...

That's what I was getting at with my post.
Offline Grunnt

JGO Wizard


Medals: 64
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #12 - Posted 2013-02-14 13:35:11 »

An approach that I like (I think Cas mentioned it at some point) is to use a Stack of Scenes. The idea is to add a Scene to the stack if it needs to be activated, and remove it once it needs to be deactivated. Then you should only update and render the topmost scene in the stack.

For this you may need to define your own Scene base class or interface, and create specific classes for scenes using inheritance (for classes) or by implementing the interface. A Scene interface could be something like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public interface IScene {

   // Initialize things needed for this scene, e.g. load assets. Called when the scene is added to the Stack.
  public void initialize();

   // Update the scene. Only called on the topmost scene in the Stack.
  public void update(float delta);

   // Render the scene. Only called on the topmost scene in the Stack.
  public void render();

   // Dispose of assets etc. that need to be disposed. Called when the scene is removed from the Stack.
  public void dispose();

}


Then implement a MenuScene, an OptionsScene, a MapScene, a BattleScene, etc...

Offline FierstArter

Junior Newbie




:3c


« Reply #13 - Posted 2013-02-14 15:44:45 »

Wow, thank you everyone for your comments. You guys are amazing  Shocked

I'm going to try out a few of this suggestions (specifically zngga and grunnt), and thanks again for all the help :x
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.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!