I saw Mario Bros game on Brent Aurelis tutorials on YouTube and basically he creates the game screen with implement screen, but I want to make my game start up with the main menu which I can't.
How can I do that?
Maybe just change file name of GameScreen to MainMenuScreen and set up your menu here ? This is just a question of naming, nothing forbids you to make your MainMenu in GameScreen and nothing forbids you to rename GameScreen class to MainMenuScreen.
Related
I have a main menu screen, which has 4 options, New Game, Load Game, Options and Exit.
Then:
New Game has more options such as difficulty, # of players + Start button.
Load Game has multiple saves to choose from together with Load and Delete options.
Options has Graphics level and Volume radio/ slider + Apply, Discard buttons.
At last, the game screen would have a pannable game window, together with an overlaying UI on the side of the screen.
My problem is, I don't know what class to use for those UI parts.
From this answer I understand that Screen is a full UI page, but it seems that creating a new Screen and then a Stage for each of those main menu options seems like an overkill, but maybe that's the way to go. I don't know if I should use Group and show/hide those depending on what the user clicks. I was also told to use Table to lay out the game screen. I'm utterly confused by all the guides I've found online. Every one seems different than the other.
The documentation is really good, but it never states how the individual parts are meant to be integrating with each other.
Is there any consensus on how to use those classes in LibGDX? Or is it a personal preference?
Screen is core libGdx part that represents one of many application screens, such as a mainscreen, a settingsscreen, the gamescreen and so on.
mainscreen may contains buttons like settings, play, level that help you to redirect on other screen.
settingsscreen may contain back button that redirect to previous mainscreen and other ui element like sound button, music button, language selection button.
It is hard to maintain different UI Screen in one ApplicationListenercontext with different required lifecycle.
so there is a Game class and Screen interface that helps to display one active screen at a time on device screen.
I think you've clear now, why we need different screens.
Now how I design one Screen Like MenuSceen that contains menu buttons, game name and similar element that act as HomeScreen.
You can use scene2d, a 2D scene graph for building UIs using a hierarchy of actors. Stage and Group are core classes of scene2d.
Stage class has a camera, SpriteBatch, and a root group and handles drawing the actors and distributing input events.
Group class is an actor that may have child actors.
At the moment my game simply consists of a play button which, when clicked, runs the game; all of this happens in the document class as follows:
stage.addChild(playBtn);
playBtn.x = 0;
playBtn.y = stage.stageHeight/2;;
playBtn.addEventListener(MouseEvent.CLICK, playGame);
The playGame() function then removes playBtn from the stage and the event listener, and runs the game code. This has been fine for me up until now, but now I want to implement a more complex menu system, which will probably consist of many buttons, graphics, etc (basically a stage select screen). My question is, what would be a more efficient way of displaying a menu on the screen, removing it when a stage is selected and then being able to return to the menu when the game is over? Obviously I'm trying to do all of this without the use of the timeline.
Use separate classes for each screen. For example a MainMenu screen class and a Game class. Then your document class becomes a simple screen switching controller, which instantiates, adds and removes screen classes.
As long as each screen only adds content into itself, and not to the stage, the document class need not know or care what's inside the screens, and removing a screen will not require each element in the screen to be removed.
As for how to add all elements to each screen, let the screen class handle it, or a symbol linked to the screen class with all your content.
I'm new to Scene2d, so i'm a little confused. Imagine that we have this two classes:
public GameScreen implements Screen {
//override methods
}
public GameX extends Game {
//override methods
}
both methods have methods like render and resize, so my question is:
Which of both is the best approach to include Stage/actors and Box2d stuff?
The Game class is actually the core of the game. It's methods are called by the GameLoop or, if some events occure.
Every game can have multiple Screens, like for example the MenuScreen, the PlayScreen, the OptionScreen or the CreditsScreen.
So a Screen repressents something like a part of a game.
The Game class can have one active Screen at a time and it calls reder() for that Screen in it's own render. The same counts for pause() and resume().
If you change the active Screen, hide() gets called for the old Screen and show() for the new Screen.
So the answer to your question is, that if your Game is really simple and does not contain different Screens, you can put the Stage inside the Game classs and treat the Game class like your one and only Screen.
If you instead have more then one Screen you should use the Screen interface and setup the Stage in one of the Screen clases.
I use both since the Game class can switch between screens setScreen. Usually I first load a loadingScreen that loads needed assets when loading is done i switch to a mainMenuScreen. But you can put some actors in the game class and load screen implementations from there, it really does not matter.
But for a clean approach I advice to just call a loading screen from the Game create method and build from there. Since each game needs at least some kind of menu and a game screen itself.
I want to make an action side scrolling game, i need some advice from you all.
I wrote my to do list here:
To do list:
Create my project's class.
Create hero MovieClip and class.
Create enemy MovieClip and class.
Create background level MovieClip and class.
Add MouseEvent, MouseClick, x y position to hero class.
Add x y position, a movement to right and left to enemy class.
Add background MovieClip to my project's class.
Add event and event listener, but still don't have a clue where to put it.
.... i don't know what's more to add to this project...
Is my to do list is bad? if yes, please tell me the right way so i can learn how to make a good plan for my project.
My advice is start coding now!
I will find out if something is missing in the road,
best,
Alvaro
I am writing a small Flash game using air for android and have encountered a slight issue.
The game has 3 screens (excluding the game screen) which are main menu, load game & create new game. On the load game and create new game screens I want to add a button which take the user back to the main menu.
I know how to add event listeners to buttons but I am wondering where do I bind the event listener for back to main menu, binding in the constructor of my main class produces an error at run time and binding after going to the frame is knocking out the other buttons when back at the main screen.
At present the app is across multiple frames (probably a better structure to this instead of loading a single frame with each menu), I am new to actionscript so I am not entirely certain on best practices for this sort of thing.
Thanks.
I recommend you to use only one frame in your Fla, then use a Document Class. In that main Class, you should place all your display objects using ActionScript.
I hope you know how to instantiate Class as library clips.