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:
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:
@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();
}