[LibGdx] Changing game to use Scene2D

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 :slight_smile:

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 :

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 :smiley: tl;dr I have never used full implementation for objects as actors, but the code looks ok besides this part:

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.

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