Batch funktioniert

master
Jonathan Hager 6 years ago
parent bfd63334c7
commit 1e58fc09b3

@ -4,15 +4,18 @@
* and open the template in the editor. * and open the template in the editor.
*/ */
package com.dungeoncrawler.control; package com.dungeoncrawler.control;
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.dungeoncrawler.view.View; import com.dungeoncrawler.view.View;
import com.dungeoncrawler.model.Dungeon; import com.dungeoncrawler.model.Dungeon;
import com.dungeoncrawler.model.entities.Player; import com.dungeoncrawler.model.entities.Player;
public class Controller extends ApplicationAdapter implements InputProcessor{ public class Controller extends ApplicationAdapter implements InputProcessor{
SpriteBatch batch;
Dungeon d; Dungeon d;
View v; View v;
Player p; Player p;
@ -21,6 +24,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
@Override @Override
public void create(){ public void create(){
batch = new SpriteBatch();
v = new View(); v = new View();
p = new Player(0,0,0); p = new Player(0,0,0);
d = new Dungeon(p); d = new Dungeon(p);
@ -29,12 +33,12 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
@Override @Override
public void render(){ public void render(){
v.render(); v.render(batch);
} }
@Override @Override
public void dispose () { public void dispose () {
v.dispose(); batch.dispose();
} }
@Override @Override

@ -1,14 +1,12 @@
package com.dungeoncrawler.view; package com.dungeoncrawler.view;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
public class View extends ApplicationAdapter { public class View {
SpriteBatch batch;
Texture b; Texture b;
Texture t; Texture t;
Texture p; Texture p;
@ -16,10 +14,7 @@ public class View extends ApplicationAdapter {
Sprite title; Sprite title;
Sprite player; Sprite player;
public View() {
@Override
public void create () {
batch = new SpriteBatch();
b = new Texture("Button.png"); b = new Texture("Button.png");
t = new Texture("Title.png"); t = new Texture("Title.png");
p = new Texture("Player.png"); p = new Texture("Player.png");
@ -38,9 +33,10 @@ public class View extends ApplicationAdapter {
} }
public void render () { public void render (SpriteBatch batch) {
Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin(); batch.begin();
title.draw(batch); title.draw(batch);
button.draw(batch); button.draw(batch);
@ -48,12 +44,6 @@ public class View extends ApplicationAdapter {
batch.end(); batch.end();
} }
public void dispose () {
batch.dispose();
}
public void move(float x, float y){ public void move(float x, float y){
player.setX(player.getX()+x); player.setX(player.getX()+x);
player.setY(player.getY()+y); player.setY(player.getY()+y);

Loading…
Cancel
Save