Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (791)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
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  
  LibGDX - Scene2D based level selection screen including locking of levels?  (Read 5089 times)
0 Members and 1 Guest are viewing this topic.
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Posted 2015-05-15 14:03:05 »

Hi guys

I'm working on an Android game but i'm a little stuck on how to create the level selection screen. Now I plan on placing some Scene2D text buttons inside a table and then placing that onto the stage. So on the first page, 9 levels might be shown. How would I go about allowing the user to scroll over to the next set of levels? Would I simply create a stage that is twice the width of the screen and then pan the camera?

Also how would I implement a star based completion system? So telling each level how many stars the user got and then feeding that information into Scene2D to display and deciding if the next level can be unlocked

I've got a YouTube video below that shows what i'm trying to explain

https://youtu.be/Ing75MIasbk?t=2m59s

Hey, you! Back to work
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #1 - Posted 2015-05-15 15:45:31 »

You can use:
- Stage > Scene2D > ScrollPane (if need scroll) > Table > Buttons > StarsLayout on Buttons (button.add(starTable).height(30))


This is a super old tutorial and need to be adapted, but I think can give you some idea. http://nexsoftware.net/wp/2013/05/09/libgdx-making-a-paged-level-selection-screen/

You can fill all the cells programatically and lock/unlock stars or levels with a saved file, like Preferences in libGDX.

_ Wink
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #2 - Posted 2015-05-15 16:31:18 »

Thank you Craft, I was heading in that direction Smiley. Will I manually have to add a listener to every single level button? Or is there a better way of handling which level is selected and then loading up that leevel

Hey, you! Back to work
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #3 - Posted 2015-05-15 17:15:51 »

Thank you Craft, I was heading in that direction Smiley. Will I manually have to add a listener to every single level button? Or is there a better way of handling which level is selected and then loading up that leevel
In my game I did something similar (without the stars), I had 40 characters to create a selection screen (with lock/unlock), so create 40 specific listeners is bad, that was my solution.

- I verify which characters are unlocked in Preferences to create the buttons.
- When the button is created you can set a name, so you can use this value to know the selected character:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
{...
button.setName("character_name");
button.addListener(characterClickListener);
table.add(button);
table.row();
...}

public ClickListener characterClickListener = new ClickListener() {
           @Override
           public void clicked (InputEvent event, float x, float y)
           {
               System.out.println("Click: " + event.getListenerActor().getName()); //print    Click: character_name
           }
       };

- You can use this value to know the next screen or send as param to create the next screen based on value.

Instead of use a name, you can use an integer, list, cell or any other method to know which button was clicked and use this value to anything else.

_ Wink
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #4 - Posted 2015-05-15 18:54:33 »

Thank you very much! Smiley This is exactly what I have done.

I gave each button a name via my for loop and then created an inner class that handles all the input. I was going to use an anonymous class but I think they look ugly Tongue

Hey, you! Back to work
Offline SauronWatchesYou

JGO Ninja


Medals: 33
Projects: 4
Exp: 2 years


Hi there! :)


« Reply #5 - Posted 2015-05-15 19:27:49 »

I've read online that instead of a switch statement to change the level, I could use something like

1  
2  
3  
String className = event.getListenerActor().getName();
Class selectedLevel = Class.forName(locationOfClassHere + className)
selectedLevel.getDeclaredConstructors();


Is this really a safe alternative? It seems that it would save a lot of time and every time I create a new level, I don't need to change the switch code Smiley

Hey, you! Back to work
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (2892 views)
2018-11-16 13:46:03

hadezbladez (1042 views)
2018-11-16 13:41:33

hadezbladez (2844 views)
2018-11-16 13:35:35

hadezbladez (558 views)
2018-11-16 13:32:03

EgonOlsen (3837 views)
2018-06-10 19:43:48

EgonOlsen (4252 views)
2018-06-10 19:43:44

EgonOlsen (2550 views)
2018-06-10 19:43:20

DesertCoockie (3365 views)
2018-05-13 18:23:11

nelsongames (3478 views)
2018-04-24 18:15:36

nelsongames (4490 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!