Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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] Changing game to use Scene2D  (Read 345 times)
0 Members and 1 Guest are viewing this topic.
Offline Stein102

Junior Member


Medals: 1



« Posted 2014-02-03 08:44:46 »

I have a game I've been working on with LibGdx and it's a top-down 2D rpg and I'm not sure if using scene2d would be the right option for me or not. I have a bunch of rendering code as it is and the game works fine, but I feel like I'd be able to get more out of scene2d for some of the features I'm going to implement in the future. The main thing I was thinking of that it would make easier would be how my game handles input. The game is tile-based and whenever you mouse over a game object, it should display what the object is (as well as a default action to perform on click) in the top corner of the game. I'll also need to add in right-click option boxes for items and game objects. For example, if you right click on a person, it may list: Talk to person, attack person, examine person, etc. I have quite a few classes that render, but I feel like I've done it in an asinine way to begin with.

 

This is my code:

https://bitbucket.org/stein102/rscl/overview

I've got rendering stuff in the following classes:

MapManager
PlayerEquipment
PlayerInventory
PlayerSkills
GameScreen
QuestTrackerUI
TabBar
UIManager

Thanks for any help Smiley
Offline Gibbo3771
« Reply #1 - Posted 2014-02-03 08:51:10 »

I have a game I've been working on with LibGdx and it's a top-down 2D rpg and I'm not sure if using scene2d would be the right option for me or not. I have a bunch of rendering code as it is and the game works fine, but I feel like I'd be able to get more out of scene2d for some of the features I'm going to implement in the future. The main thing I was thinking of that it would make easier would be how my game handles input. The game is tile-based and whenever you mouse over a game object, it should display what the object is (as well as a default action to perform on click) in the top corner of the game. I'll also need to add in right-click option boxes for items and game objects. For example, if you right click on a person, it may list: Talk to person, attack person, examine person, etc. I have quite a few classes that render, but I feel like I've done it in an asinine way to begin with.

 

This is my code:

https://bitbucket.org/stein102/rscl/overview

I've got rendering stuff in the following classes:

MapManager
PlayerEquipment
PlayerInventory
PlayerSkills
GameScreen
QuestTrackerUI
TabBar
UIManager

Thanks for any help Smiley

Scene2D is crazy flexible, the main problem people have is figuring out how Skin and that works.

For what I have read in your post, Scene2D would work wonders for you. Things like right click menus require some arsing about to get working without Scene2D, if you used Scene2D all you would need is a table in the clickable area and whenever you right click on a tile, you get it's type and properties, pass it in a constructor for an object maybe named "RightClickButton", which simply draws it at the x y coord of the mouse pointer, then set a boolean to true so the game knows one is already open.

Reallly it is a very powerful tool and the time spent implementing a decent scene2d UI manager pays off, defo.

Like it will remove all this horrid shit :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
if(!dragged){
         for (int ny = 0; ny < 7; ny++) {
            for (int nx = 0; nx < 4; nx++) {
               if (inventoryList[nx][ny] != null) {
                  batch.draw(inventoryList[nx][ny].getSprite(), x + (nx * 65), y - (ny * 65));
               }
            }
         }
      //Rendering for dragging
     }else{
         for (int ny = 0; ny < 7; ny++) {
            for (int nx = 0; nx < 4; nx++) {
               if (inventoryList[nx][ny] != null) {
                  if(nx==selectedX && ny==selectedY){
                     batch.draw(inventoryList[nx][ny].getSprite(),draggedX-(65/2),draggedY-(65/2));
                  }else{
                     batch.draw(inventoryList[nx][ny].getSprite(), x + (nx * 65), y - (ny * 65));
                  }
               }
            }
         }
      }
      batch.end();
   }


Not that your code is horrible but all Scene2D needs to draw is a stage, table and an object, it takes care of everything else like the drawable and that in the background for you.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Stein102

Junior Member


Medals: 1



« Reply #2 - Posted 2014-02-03 22:03:53 »

I have a game I've been working on with LibGdx and it's a top-down 2D rpg and I'm not sure if using scene2d would be the right option for me or not. I have a bunch of rendering code as it is and the game works fine, but I feel like I'd be able to get more out of scene2d for some of the features I'm going to implement in the future. The main thing I was thinking of that it would make easier would be how my game handles input. The game is tile-based and whenever you mouse over a game object, it should display what the object is (as well as a default action to perform on click) in the top corner of the game. I'll also need to add in right-click option boxes for items and game objects. For example, if you right click on a person, it may list: Talk to person, attack person, examine person, etc. I have quite a few classes that render, but I feel like I've done it in an asinine way to begin with.

 

This is my code:

https://bitbucket.org/stein102/rscl/overview

I've got rendering stuff in the following classes:

MapManager
PlayerEquipment
PlayerInventory
PlayerSkills
GameScreen
QuestTrackerUI
TabBar
UIManager

Thanks for any help Smiley

Scene2D is crazy flexible, the main problem people have is figuring out how Skin and that works.

For what I have read in your post, Scene2D would work wonders for you. Things like right click menus require some arsing about to get working without Scene2D, if you used Scene2D all you would need is a table in the clickable area and whenever you right click on a tile, you get it's type and properties, pass it in a constructor for an object maybe named "RightClickButton", which simply draws it at the x y coord of the mouse pointer, then set a boolean to true so the game knows one is already open.

Reallly it is a very powerful tool and the time spent implementing a decent scene2d UI manager pays off, defo.

Like it will remove all this horrid shit :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
if(!dragged){
         for (int ny = 0; ny < 7; ny++) {
            for (int nx = 0; nx < 4; nx++) {
               if (inventoryList[nx][ny] != null) {
                  batch.draw(inventoryList[nx][ny].getSprite(), x + (nx * 65), y - (ny * 65));
               }
            }
         }
      //Rendering for dragging
     }else{
         for (int ny = 0; ny < 7; ny++) {
            for (int nx = 0; nx < 4; nx++) {
               if (inventoryList[nx][ny] != null) {
                  if(nx==selectedX && ny==selectedY){
                     batch.draw(inventoryList[nx][ny].getSprite(),draggedX-(65/2),draggedY-(65/2));
                  }else{
                     batch.draw(inventoryList[nx][ny].getSprite(), x + (nx * 65), y - (ny * 65));
                  }
               }
            }
         }
      }
      batch.end();
   }


Not that your code is horrible but all Scene2D needs to draw is a stage, table and an object, it takes care of everything else like the drawable and that in the background for you.

Okay, so getting the right-click menu set up sounds pretty simple to get working once I have the rest set up. I'll have to work on that soon, but it'll take me a little while to get the rest of the game into scene2D as well. I've never really used it before so it'll take some getting used to. I've got a branch called "graphicsChange" in my repo and I've moved the player and NPCs to scene2D, do you think you could take a look and see if I've done it properly?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Gibbo3771
« Reply #3 - Posted 2014-02-04 10:19:15 »

I have a game I've been working on with LibGdx and it's a top-down 2D rpg and I'm not sure if using scene2d would be the right option for me or not. I have a bunch of rendering code as it is and the game works fine, but I feel like I'd be able to get more out of scene2d for some of the features I'm going to implement in the future. The main thing I was thinking of that it would make easier would be how my game handles input. The game is tile-based and whenever you mouse over a game object, it should display what the object is (as well as a default action to perform on click) in the top corner of the game. I'll also need to add in right-click option boxes for items and game objects. For example, if you right click on a person, it may list: Talk to person, attack person, examine person, etc. I have quite a few classes that render, but I feel like I've done it in an asinine way to begin with.

 

This is my code:

https://bitbucket.org/stein102/rscl/overview

I've got rendering stuff in the following classes:

MapManager
PlayerEquipment
PlayerInventory
PlayerSkills
GameScreen
QuestTrackerUI
TabBar
UIManager

Thanks for any help Smiley

Scene2D is crazy flexible, the main problem people have is figuring out how Skin and that works.

For what I have read in your post, Scene2D would work wonders for you. Things like right click menus require some arsing about to get working without Scene2D, if you used Scene2D all you would need is a table in the clickable area and whenever you right click on a tile, you get it's type and properties, pass it in a constructor for an object maybe named "RightClickButton", which simply draws it at the x y coord of the mouse pointer, then set a boolean to true so the game knows one is already open.

Reallly it is a very powerful tool and the time spent implementing a decent scene2d UI manager pays off, defo.

Like it will remove all this horrid shit :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
if(!dragged){
         for (int ny = 0; ny < 7; ny++) {
            for (int nx = 0; nx < 4; nx++) {
               if (inventoryList[nx][ny] != null) {
                  batch.draw(inventoryList[nx][ny].getSprite(), x + (nx * 65), y - (ny * 65));
               }
            }
         }
      //Rendering for dragging
     }else{
         for (int ny = 0; ny < 7; ny++) {
            for (int nx = 0; nx < 4; nx++) {
               if (inventoryList[nx][ny] != null) {
                  if(nx==selectedX && ny==selectedY){
                     batch.draw(inventoryList[nx][ny].getSprite(),draggedX-(65/2),draggedY-(65/2));
                  }else{
                     batch.draw(inventoryList[nx][ny].getSprite(), x + (nx * 65), y - (ny * 65));
                  }
               }
            }
         }
      }
      batch.end();
   }


Not that your code is horrible but all Scene2D needs to draw is a stage, table and an object, it takes care of everything else like the drawable and that in the background for you.

Okay, so getting the right-click menu set up sounds pretty simple to get working once I have the rest set up. I'll have to work on that soon, but it'll take me a little while to get the rest of the game into scene2D as well. I've never really used it before so it'll take some getting used to. I've got a branch called "graphicsChange" in my repo and I've moved the player and NPCs to scene2D, do you think you could take a look and see if I've done it properly?

The code looks perfectly fine but are you planning to use a full Scene2D implementation and all? As in every object is an actor and Scene2D handles everything from collision to input? I have only ever used Scene2D for user interfaces and menus.

The last thing I used it for was to create a basic menu system for a project, usual play, settings, exit and transitions etc etc. Then in the actual game I needed a right click menu, basically all it done was when I right clicked on an object, the logic would check if my cursor was clicked within the x and y boundaries of the box2d body, then if so it would get that object and retrieve the information. The menu only had 2 options, Select Target and Lock but depending on logic, the target might already be locked or selected so Scene2D needed to know what to draw in it's place and what the button listener will do.

Sorry I am ranting Cheesy tl;dr I have never used full implementation for objects as actors, but the code looks ok besides this part:

1  
2  
3  
4  
5  
gameStage.act();
+      gameStage.draw();
+      
       //UI Rendering
      uiManager.stage.draw();


You have 2 stages, if it was me I would only have 1 stage and use tables, so give your UIManager a table of its own, no point in having multiple draw calls.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #4 - Posted 2014-02-04 15:41:19 »

Two stages is only useful if they have different cameras, otherwise you should have one.

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.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!