i made a game in libGDX for android. I made a main screen that extends game, i also have blank screen and a game screen where you actually play the game. My question is where do i create and where do i render the game. i tried to create a texture in the main screen and render in the game screen. but i get erros.
Main Screen:
package com.mygdx.paper;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Main extends Game {
Blank blankScreen;
Game gameScreen;
@Override
public void create() {
blackScreen = new blankScreen(this);
gameScreen = new blankScreen(this);
setScreen(blankScreen);
}
}
Blank Screen:
package com.mygdx.paper;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
public class Blank implements Screen {
Main main;
public Blank(Main main) {
this.main= main;
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (Gdx.input.isTouched())
main.setScreen(main.gameScreen);
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
}
@Override
public void hide() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
Game Sceen
My game screen has everything in it like create, render. But it does not work when i click on the blank screen.
Here:
blackScreen = new blankScreen(this);
gameScreen = new blankScreen(this);
you set a new blankScreen instance for both screens: blackScreen and gameScreen. So after touching your blankScreen you will see anther blankScreen an so on..
You might actually want to actually assign a GameScreen (..or whatever your games screen's class is actually called) instead:
gameScreen = new GameScreen(this);
BTW: there is a really nice tutorial about screens in libgdx