Libgdx for android shows black before main screen - java

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.

Related

Scene2D actor flashing on screen for 1 frame when supposed to be invisible

I am trying to create an actor with Scene2D, that appears on the screen only when a certain event is triggered. To do so, I use the following code:
blackRectangle.addAction(Actions.alpha(0));
optionalStage.addActor(blackRectangle);
blackRectangle.addAction(Actions.delay(0.5f,Actions.alpha(0.7f, 0.5f)));
The problem I am having is that when the rectangle is added to the optionalStage, the rectangle appears on the screen for 1 frame, disappears, and then proceeds to fade in as supposed to.
I tried playing with
actor.setVisible(true/false);
but no luck. Is there a way to prevent that "flash" when the actor is added to the stage, even though its alpha is 0?
Change this :
blackRectangle.addAction(Actions.alpha(0));
to
blackRectangle.getColor().a=0;

Animating Crossfading between two images - Splash Screen

I am creating a splash screen for my app using multiple images. I have one main image that will be displayed as a Logo; behind the logo I intend to have two images - a green cloud, and a blue cloud, fading in and out a few times so it will create a kind of pulsing glow effect behind the logo. What is the best way to implement this type of effect? Basically the main image will stay static while the other two images switch back and forth from one to the other until the end of the splash intro. Thanks in advance for the help! BTW I am using Eclipse.
Have two images stacked - one way is in ht linear layout keep blue cloud as background and in the frame layout keep an ImageView. In the ImageView hold the green cloud. Now make the transparency of the image in the frame layout ("green cloud") fade in and fade out with its transparency. Call setAlpha in a loop -cycle the the argument to set Alpha - 0 is fully transparent wherein "blue cloud" is visible and 255 is fully opaque - "green cloud" is visible.

Slowing down the speed of drawing an object

I am drawing a gesture on the screen. Can we control the speed of drawing the gesture ?? It is being displayed but directly without showing how it was drawn.. I tried using sleep(), wait() methods but didn't work. I want it show the path how the gesture was drawn slowly.. Is it possible ?

Android: Creating an Item Fade Animation when Scrolling (Example Included)

I've seen this specific animation in certain apps where when scrolled, the first item on the window (most commonly an ImageView) gets faded out when scrolling down. Here's two screenshots that display the animated change:
This is from a fashion app named "Polyvore":
The image above displays an ImageView which gets faded out when scrolled. Animated more like.
And after scrolling a bit..
And it ultimately fades out along with the scrolling. Pardon me for I don't know what this 'View' or animation is called. I've seen this in the Google Play Music app as well. How do I implement this?
For anyone else looking for this specific effect. It's known as a Parallax effect. Check this link:
How to do the new PlayStore parallax effect

Android Drawing on Multiple Canvas Multiple Activities

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

Categories

Resources