I am creating an android application composed of three screens and a game object that is passed between them.
A MenuScreen that is only used when the game is started. This makes no change to the GameObj and simply sets the screen to the GameScreen.
The GameScreen where the player dodges falling blocks while the GameObj.timer measures the time the player is alive. When the player collides with a falling object, the screen is set to the EndScreen.
The EndScreen lists the time the player was alive by accessing the GameObj.Timer and has a button to set the screen back to the GameScreen.
The information is passed from the GameScreen to the EndScreen properly the first time, but when the Reset button is pressed and the screen is set to GameScreen, the timer is NOT reset back to 0 and the blocks from the previous game are still present.
Initially I had used GameObj.setScreen(new GameScreen(this)); but this creates a leak because the previous GameScreen is never deleted.
I am wondering if there is a way in LibGDX to dispose the entire screen (rather than just the textures) and create a new one?
Thanks in advance!
Related
I've encountered something strange in my LibGDX project. I'm currently using a Music instance to play my ambient music, which itself is a copy of another external static Music instance. My problem comes when I swap screens and then swap back to the previous screen - the audio playback becomes noticeably higher in volume even though the music.getVolume() returns the same value. I've already made sure that I stop the music from playing and I dispose of the music object, so I don't think it's because more than one music instance is overlapping.
Code:
//In my assets class
public static final Music RAIN_AMBIENT_MUSIC = Gdx.audio.newMusic(Gdx.files.internal("music/ambient/rain.mp3"));
//In my screen's show() method
background_music_1 = Assets.RAIN_AMBIENT_MUSIC;
background_music_1.setLooping(true);
background_music_1.play();
background_music_1.setVolume(0.5f);
//In my screen's hide() method
background_music_1.stop();
dispose();
//In my screen's dispose method
background_music_1.dispose();
Any ideas?
This is for a game I'm building where sprites are constantly overlapping since their spawn locations are randomly generated. The player must tap some sprite at a certain time. The problem arrives if the they need to tap the bottom sprite of 2 or more overlapping sprites. The touch is only registered for one of the sprites which makes the game impossible sometimes.
Is it possible to get an array of all sprites in the touch location?
Nevermind I figured it out. I just had to set the return value of onAreaTouched to false.
As soon as a sprite's onAreaTouched returns true, the touch event ends.
I am new to make animation and graphics in Android. I am trying to create a Quiz type of game. and it is created . Now I am try to show the diff Levels(Level 1,Level 2...) to player. When a Player finish Level 1 , I want to move that Player Avatar to One Level 1 to Level 2 using some Animation(Ex: Like Candy Crush). Player Avatar moves to next level Automatically. Is there any Lib to animate is Avatar moving to next level.
And is it possible to switch between my Quiz Game Activity and Game Level Screen using Libary.
It's a pretty general question so I can only suggest getting into Android animation tools. There right tool for the job is probably PropertyAnimator animating View (avatar) position as described here.
I am making a game in LibGDX, and I have noticed that when my game is launched a black screen is shown for a few moments before the white screen of my game is drawn.
I have set the background of my app's theme to be a different color with android:windowBackground in my app's style.xml, and the preview window shows that color. However, right before the main screen of my app loads, the screen goes black for a moment before displaying the main screen.
I've tried setting Gdx.gl.glClearColor(1,1,1,1) in the main activity and Game class of my game, but the black screen still shows for a moment before drawing the main screen.
The only way I've found to fix this is to set the android:windowDisablePreview to true, but that disables the preview window all together.
Is there any way to fix this without disabling the preview?
In addition to shifting objects creation to constructor, you also need to shift the ApplicationListener object creation in Activity class's constructor.
The black screen is probably because of the time delay between start of Activity.onCreate() call and end of ApplicationListener.show() call.Try to measure it using a timer or simply System.currentTimeMillis() so the difference would be visible.
This should improve the situation if not eliminate the problem.
Here is my problem:
I currently have on Canvas in my main game activity that is constantly being drawn with OnDraw(). This is a board game with two players. When a player's turn begins, there are many options that the player can do, and I would like all of this to be put in a different class.
Also, this new class must draw NEW animations on top of the current canvas. These animations will came from attacks (I haven't even looked into animations yet). So basically I would like another canvas on top of the main one.
Furthermore, the OnDraw function in the main activity must PAUSE and wait for the other class with the canvas on top to complete.
Let me try and summarize this: I have a main game class with one canvas. This class handles the players' turns and setting up the game. It also draws the playing field. I need another class, when it is a player's turn, to draw animations and other things on top of the current canvas.
Can anybody help me with this?
NOTE : I looked into Fragments and FragmentManager, but it seems I can only use XML Views with that and not RenderViews.
Thank you!
You might want to consider using multiple bitmaps as buffers and then just add them on top of each other before rendering to the canvas.
There is a nice example in the "samples" pack that comes with the sdk that shows of how you can merge bitmaps on top of each other.
Let me know if you want to try this out and need some more pointers on how to do it :)