View difference between Paste ID: W2GLvDYZ and 08ZidFEJ
SHOW: | | - or go back to the newest paste.
1
Error:
2
Exception in thread "LWJGL Application" java.lang.IllegalStateException: SpriteBatch.end must be called before begin.
3
	at com.badlogic.gdx.graphics.g2d.SpriteBatch.begin(SpriteBatch.java:167)
4
	at com.shootthefacedontdie.game.shotthefacedontdie.screen.game.com.MainMenu.render(MainMenu.java:35)
5
	at com.shootthefacedontdie.game.MainClass.render(MainClass.java:33)
6
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:225)
7
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
8
9
package com.shootthefacedontdie.game;
10
11
import com.badlogic.gdx.Game;
12
import com.badlogic.gdx.Gdx;
13
import com.badlogic.gdx.graphics.GL20;
14
import com.badlogic.gdx.graphics.g2d.BitmapFont;
15
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
16
import com.shootthefacedontdie.game.shotthefacedontdie.screen.game.com.GameScreen;
17
import com.shootthefacedontdie.game.shotthefacedontdie.screen.game.com.MainMenu;
18
19
public class MainClass extends Game {
20
21
	public SpriteBatch batch;
22
	public BitmapFont font;
23
	private GameScreen gameScreen;
24
	private MainMenu mainMenu;
25
26
	@Override
27
	public void create () {
28
		batch=new SpriteBatch();
29
		gameScreen=new GameScreen(this);
30
		mainMenu=new MainMenu(this);
31
		gameScreen.create();
32
33
	}
34
35
	@Override
36
	public void render()
37
	{
38
		batch.begin();
39
		Gdx.gl.glClearColor(0, 0, 0, 0);
40
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
41
		mainMenu.render(60);
42
		gameScreen.render(60);
43
		batch.end();
44
	}
45
46
	@Override
47
	public void dispose ()
48
	{
49
		gameScreen.dispose();
50
		batch.dispose();
51
	}
52
}
53
54
package com.shootthefacedontdie.game.shotthefacedontdie.screen.game.com;
55
56
import com.badlogic.gdx.Gdx;
57
import com.badlogic.gdx.Screen;
58
import com.badlogic.gdx.graphics.GL20;
59
import com.badlogic.gdx.graphics.OrthographicCamera;
60
import com.shootthefacedontdie.game.MainClass;
61
62
/**
63
 * Created by marcel on 29.01.17.
64
 */
65
66
public class MainMenu implements Screen{
67
68
    private final MainClass game;
69
70
    private OrthographicCamera camera;
71
72
    public MainMenu(final MainClass gam) {
73
        this.game = gam;
74
75
        camera = new OrthographicCamera();
76
        camera.setToOrtho(false, 800, 480);
77
78
    }
79
80
    @Override
81
    public void render(float delta) {
82
        Gdx.gl.glClearColor(0, 0, 0.2f, 1);
83
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
84
85
        camera.update();
86
        game.batch.setProjectionMatrix(camera.combined);
87
88
        game.batch.begin();
89
        game.font.draw(game.batch, "Welcome to MainClass!!! ", 100, 150);
90
        game.font.draw(game.batch, "Tap anywhere to begin!", 100, 100);
91
        game.batch.end();
92
93
        if (Gdx.input.isTouched()) {
94
            game.setScreen(new GameScreen(game));
95
            dispose();
96
        }
97
98
    }
99
100
    @Override
101
    public void show() {
102
103
    }
104
105
    @Override
106
    public void resize(int width, int height) {
107
108
    }
109
110
    @Override
111
    public void pause() {
112
113
    }
114
115
    @Override
116
    public void resume() {
117
118
    }
119
120
    @Override
121
    public void hide() {
122
123
    }
124
125
    @Override
126
    public void dispose() {
127
128
    }
129
}