How can I switch the screen and still save the progress of the current game? For example I have an additional screen, when you press tab key, that shows some information about the player (attributes, stats, etc.), but when you switch the screen again to resume your game the show method is called again and you lose everything... The only method I know is that before you hide the screen to save the game in some format and load it in show but I highly doubt that this is the proper way to do it, as there would be a real performance issue when you switch the screens very fast... I need a way to keep the data from the previous screen and not initialize it every time the screen is showed. This would also apply to the skill tree and inventory which also needs to be saved for the entire game session. The filed loading from save game file format should be done only once not every time a screen changes. Any ideas?
Related
I am creating a project like youtube shorts.
where i have implemented Viewpager2(modal contains only videoview) with RecyclerviewAdapter, everything is ok, but problem is when we swiping both video playing at same time, and some stuck in intial point of scrolling.
So, 1. how to play one video at a time only when screen is fully visible, and second video which coming by scrolling remain pauses or black screen until screen is fully visible?
for smoothness i tried setoffpagelimit method, it plays multiple audio without any scrolling, i think with the solution of first question 2nf question also will solved.
I have an application in java swing and geotools. I have displayed a map image and trying to add images as layers to it. When it adds layer it blinks and after some time at the call to addLayer function map image and other few layers disappear for some time. How to stop this? I am loging all the information at the same time in SQLite and then to my own customised file.
I have stopped trying refreshing all after addLayer function call. The all process should work smoothly without blinking and disappearing. Please Help.
The gt-swing module is really only intended for simple demonstrations. If you intend to use it in production you should add in off screen buffering to allow "fast" refreshes of the map without rereading all the displayed data.
Here's my case. I have three different types of screens:
MainMenuScreen
Has a "Start" button for switching to the GameScreen. Also lets player change basic game settings.
GameScreen
The actual playable game (where the player character runs and jumps).
GameOverScreen
Screen that plays an animation and then displays a menu that lets the player start the game again (i.e. switch to GameScreen) or return the main menu (i.e. switch to MainMenuScreen).
Am I better off storing my Screens in variables and reusing them when I switch screens, or is it better to dispose of each Screen when I'm done with it and then create a new instance of the screen type I intend to switch to?
And would the answer be different in a case where Screen switching is more frequent (like between an overworld Screen and a battle Screen in a game like Final Fantasy or Pokemon)?
Thanks!
In my opinion you should reuse Screens, which are used frequently and dispose and recreate Screens not used that often.
In your example the GameScreen, GameOverScreen and MainMenuScreen should all be reused, as they are directly connected to each other:
As soon as a player starts a game, it is possible, that he dies. Then the GameOverScreen is shown and directly after that the MainMenuScreen is shown. So the user does not need to switch to those Screens manually.
The OptionsScreen instead, could be disposed and recreated every time, because usualy you open the OptionScreen only a few times. Also it is not directly connected to any other Screen, but the user needs to "force" the game to open the OptionScreen.
But as long as there aren't too many Screens, reusing shouldn't be a problem.
In your second example, the Screens are used even more often, so they definitly should be reused.
EDIT:
As #EssEllDee mentioned, you should also make use of hide() and show(). Those methods get called by Libgdx, when you switch the Screen and they can be used to dispose/recreate heavy ressources. For example, you might dispose Textures used for the game, when you switch to the GameOverScreen and reload them, when switching to the GameScreen.
So to expand on the question stated, to my best understanding android apps have a set of activities such as the default activity_main.xml and you could even generate a login screen (activity_login.xml). After fiddling around with it I sort of feel comfortable with the way buttons work, yadda yadda, but my problem emerges when I want to create a game activity. I am not concerned about that part, I would just make another activity (activity_gameplay.xml) that I would run the game on. My problem is that I want to render my own custom buttons onto the screen which would be transparent and would be stationary while the actual game environment would be moving. Such as in Minecraft(android version obviously).
So to conclude I need to know how to render custom buttons, and though not included in the above, how to position the buttons accordingly sense the XML way only allows stuff such as upper left-hand corner etc.
My game app has many complex graphical elements and I am worried that having a banner ad continuously on screen will detract too much from the game. My plan is that the user will be able to play each "level" in the game using the full screen without any ads, but upon completion of each level an ad will slide in, on top of the top part of the screen. Presumably this means I have to somehow create a layout programatically that will appear on top of the existing screen layout. Can this be done? If so how?
It can be done.
Afaik you simply have to create a layout which is android:backgroundcolor="transparent".
Else you could do it so you started a new activity on each level completion?