Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED]Weird Screen Flicker problem when implementing multiple screens...  (Read 1847 times)
0 Members and 1 Guest are viewing this topic.
Offline Bassex96

Senior Member


Medals: 4



« Posted 2013-04-18 03:26:31 »

Okay guys, another noob question coming...I've decided to implement different screens into my brickbreaker game, so I moved all of my game.java code into GameScreen.java and changed the necessary things (created the show method and moved all of create() to it) and i've created a splash screen. (splash.java)

I've got it working, it loads the splash screen which just changes the screen to white right now and when you click on it, it loads the game from GameScreen. As soon as I click on the screen, it changes but flickers from black to white over and over again like it's still calling the splash screen...Also, there is a trace of images from the ball that are behind it and none of the bricks are disappearing. I've taken a picture which really doesn't show the screen flashing.


Below is my Splash.java code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
package com.psillicoder.brickbreaker;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Splash implements Screen {

   private Game MyGame;
   private SpriteBatch batch;
   public boolean isActive;
   
   public Splash(Game g) {
      MyGame = g;
     
   }
   
   
   public void render(float delta) {
      if (isActive) {
      Gdx.gl.glClearColor(1, 1, 1, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     
      if(Gdx.input.justTouched()) {
            MyGame.setScreen(new GameScreen(MyGame));
            System.out.println("TESTING");
         }
     
      }
   
   }
   @Override
   public void resize(int width, int height) {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void show() {
      isActive = true;
     
   }

   @Override
   public void hide() {
      isActive = false;
     
   }

   @Override
   public void pause() {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void resume() {
      // TODO Auto-generated method stub
     
   }

   @Override
   public void dispose() {
      // TODO Auto-generated method stub
     
   }

}


Below is the show() part of my GameScreen:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
@Override
   public void show() {
      isActive = true;
   
      float w = Gdx.graphics.getWidth();
      float h = Gdx.graphics.getHeight();
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     
     
      //Initialize objects
     ball = new Ball();
      paddle = new Paddle();
      level = new Level();
                 
      camera = new OrthographicCamera(1, h/w);
      batch = new SpriteBatch();
      //Text stuff
     font = new BitmapFont();
      textWidth = font.getBounds(strBricks).width;
      textHeight = font.getBounds(strBricks).height;
     
      //Load level Bricks
     level.LoadBricks();
   }
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 131
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2013-04-18 05:00:06 »

Didn't read your code too thoroughly, but maybe try adding camera.update() to your render method? It only helps a bit in my game, but idk about your game - it would be helpful to have the code of the ball, paddle, level.
Offline Bassex96

Senior Member


Medals: 4



« Reply #2 - Posted 2013-04-18 05:08:52 »

GameScreen.java
http://pastebin.com/kYv5QhJi

MyGame.java
http://pastebin.com/kYv5QhJi

Splash.java
http://pastebin.com/HtiXFcuM

Level.java
http://pastebin.com/J6c6QezV

Ball.java
http://pastebin.com/G6zVJrQL

Brick.java
http://pastebin.com/bgaCjvpL


It has to be just something small that i'm not doing. I've done so many tests and can't narrow it down to any of my methods.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bassex96

Senior Member


Medals: 4



« Reply #3 - Posted 2013-04-18 19:27:40 »

Anybody have a clue? This is driving my crazy. I've tried everything.
Offline Giovanni

Junior Member




chop!


« Reply #4 - Posted 2013-04-18 19:42:54 »


Below is the show() part of my GameScreen:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
@Override
   public void show() {
      isActive = true;
   
      float w = Gdx.graphics.getWidth();
      float h = Gdx.graphics.getHeight();
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     
     
      //Initialize objects
     ball = new Ball();
      paddle = new Paddle();
      level = new Level();
                 
      camera = new OrthographicCamera(1, h/w);
      batch = new SpriteBatch();
      //Text stuff
     font = new BitmapFont();
      textWidth = font.getBounds(strBricks).width;
      textHeight = font.getBounds(strBricks).height;
     
      //Load level Bricks
     level.LoadBricks();
   }


I don't really know when this is called but it looks a little bit odd to me. I guess this is some rendering call. But why are you creating/initializing your stuff there? If that really is a rendering call then you are doing that every frame and that's not really good. Put your object creation somewhere else like in an init() method or whatever and only update objects that really have to be updated every frame in the show() method.
Offline Bassex96

Senior Member


Medals: 4



« Reply #5 - Posted 2013-04-18 19:52:00 »

I'm using libGDX and followed a few tutorials for using different screens. From the tutorial I read, you don't use the create() method but instead use show() as it's only called once when the screen is brought to active.

*EDIT*
Yeah, I added a system.out method and it's only called once.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 131
Projects: 4
Exp: 3 years



« Reply #6 - Posted 2013-04-18 20:29:30 »

show() isn't the loop, render() is. As for the original problem, you don't need a render() method in your splash screen, instead try doing something like this in the show() method
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
super.show();

        // retrieve the splash image's region from the atlas
       AtlasRegion splashRegion = getAtlas().findRegion( "splash-screen/splash-image" );
        Drawable splashDrawable = new TextureRegionDrawable( splashRegion );

        // here we create the splash image actor; its size is set when the
       // resize() method gets called
       splashImage = new Image( splashDrawable, Scaling.stretch );
        splashImage.setFillParent( true );

        // this is needed for the fade-in effect to work correctly; we're just
       // making the image completely transparent
       splashImage.getColor().a = 0f;

        // configure the fade-in/out effect on the splash image
       splashImage.addAction( sequence( fadeIn( 0.75f ), delay( 1.75f ), fadeOut( 0.75f ),
            new Action() {
                @Override
                public boolean act(
                    float delta )
                {
                    // the last action will move to the next screen
                   game.setScreen( new MenuScreen( game ) );
                    return true;
                }
            } ) );

        // and finally we add the actor to the stage
       stage.addActor( splashImage );
(ripped off https://code.google.com/p/steigert-libgdx/source/browse/trunk/tyrian-game/src/com/blogspot/steigert/tyrian/screens/SplashScreen.java). The most important part of this code is how he uses the Action class. I suspect that you may be re-loading the game screen every time a touch is detected.
Offline Bassex96

Senior Member


Medals: 4



« Reply #7 - Posted 2013-04-18 21:57:13 »

Ithought that was the case, but I used some debug outputs and it's only run one time. The splash screen and everything works when I click the screen. It goes to the gamescreen and that's when the problem starts.

I have to have the render loop in my splashscreen. It's more like a menu screen. I tried to take the render out and it gave me an error saying i'm missing my render loop.

It's so confusing. Everything was working fine before I added the different screen. It's definitely something to do with gameScreen. I just can't figure out what.
Offline Bassex96

Senior Member


Medals: 4



« Reply #8 - Posted 2013-04-18 23:13:18 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
   public void show() {
      //isActive = true;
 
      float w = Gdx.graphics.getWidth();
      float h = Gdx.graphics.getHeight();
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     
      System.out.println("SHOWN1");


I commented everything else out under show, so this is the only line of code that is being called now and it's still flickering. If I comment out gdx.gl.glClear(gl20.glcolorbufferbit), the screen just stays white and doesn't flicker.

There has to be a call im forgetting to do or a variable i'm forgetting to set..It's gotta be something simple. I've searched and searched and searched.
Offline Bassex96

Senior Member


Medals: 4



« Reply #9 - Posted 2013-04-18 23:23:10 »

WOOHOO! Solved it. I knew it was something simple. I was calling
1  
2  
3  
4  
5  
         float w = Gdx.graphics.getWidth();
         float h = Gdx.graphics.getHeight();
         Gdx.gl.glClearColor(0, 0, 0, 1);
         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
         camera = new OrthographicCamera(1, h/w);


in my show method but it needed to be in the render method.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 131
Projects: 4
Exp: 3 years



« Reply #10 - Posted 2013-04-19 03:56:19 »

1  
camera = new OrthographicCamera(1, h/w);

certainly should not be in the render method...you never instantiate objects in your game loop. (should be in your constructor/show() method) everything else, yes.
Offline Bassex96

Senior Member


Medals: 4



« Reply #11 - Posted 2013-04-19 15:31:56 »

1  
camera = new OrthographicCamera(1, h/w);

certainly should not be in the render method...you never instantiate objects in your game loop. (should be in your constructor/show() method) everything else, yes.

I thought that too, but when I put that part in the show/create method, I get an error on h/w..which normally would make sense, but I don't set h or w anywhere, so i'm not sure why it works in the render method but not there. i'll take it out.

*EDIT* I'm an idiot. Sorry. I completely looked over where I was setting h and w right above it.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (25 views)
2014-09-21 02:42:18

BurntPizza (16 views)
2014-09-21 01:30:30

moogie (19 views)
2014-09-21 00:26:15

UprightPath (26 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (44 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (100 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56

mitcheeb (71 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!