I have 2 screens and wish to be able to move between them. One opens on load and this one is called gameScreen. the other is called Another. The game doesn't do anything. i'm just playing with libgdx. This is my code
main class which opens gameScreen
the main class, MyGdxGame, contains this
package com.me.mygdxgame;
import com.badlogic.gdx.Game;
import com.me.mygdxgame.gameScreen;
public class MyGdxGame extends Game{
public gameScreen game;
@Override
public void create() {
game = new gameScreen(this);
setScreen(game);
}
}
gameScreen is
package com.me.mygdxgame;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
public class gameScreen extends Game implements Screen{
OrthographicCamera camera;
private MyGdxGame game;
public Another game2;
public gameScreen (MyGdxGame game) {
this.game=game;
camera=new OrthographicCamera();
camera.setToOrtho(true,1080,1920);
}
@Override
public void render(float delta) {
// TODO Auto-generated method stub
Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.update();
if(Gdx.input.isTouched()){
game2=new Another(this);
setScreen(game2);
}
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@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
}
@Override
public void create() {
// TODO Auto-generated method stub
}
}
and Another is
package com.me.mygdxgame;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Another extends Game implements Screen{
OrthographicCamera cameraa;
SpriteBatch batch;
Sprite hello;
Texture thello;
private gameScreen game;
public Another(gameScreen game){
this.game=game;
cameraa=new OrthographicCamera();
cameraa.setToOrtho(true,1080,1920);
batch=new SpriteBatch();
thello = new Texture(Gdx.files.internal("data/libgdx.png"));
thello.setFilter(TextureFilter.Linear, TextureFilter.Linear);
hello = new Sprite(thello);
hello.flip(false, true);
}
@Override
public void render(float delta) {
// TODO Auto-generated method stub
Gdx.gl.glClearColor(0F, 0F, 1F, 1F);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
cameraa.update();
if(Gdx.input.isTouched()){
}
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void show() {
// TODO Auto-generated method stub
Gdx.gl.glClearColor(0F, 0F, 1F, 1F);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(cameraa.combined);
cameraa.update();
batch.begin();
batch.draw(hello,0,0);
batch.end();
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@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
}
@Override
public void create() {
// TODO Auto-generated method stub
}
}
i used rather unusual names such as cameraa and gamee. this is because this whole project is a test, like i said i i couldnt be bothered setting proper names