Pass spritebatch instance to all entity's render methods

Scale spritebatch and shaperenderer projections to PIXEL_PER_METER,
no longer have to scale in each entity's render method
Use a separate spritebatch for font rendering
Dispose the texture atlas
This commit is contained in:
2018-11-22 15:44:13 +04:00
parent 70f142c2fa
commit 53feedf407
11 changed files with 60 additions and 54 deletions

View File

@ -10,9 +10,11 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.me.brickbuster.state.MenuState;
import com.me.brickbuster.state.PlayState;
public class BrickBuster extends Game {
@ -26,8 +28,8 @@ public class BrickBuster extends Game {
public BitmapFont font;
public SpriteBatch sb;
public SpriteBatch fb;
public ShapeRenderer sr;
public PolygonSpriteBatch pb;
public AssetManager assets;
@ -42,8 +44,8 @@ public class BrickBuster extends Game {
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
sb = new SpriteBatch();
fb = new SpriteBatch();
sr = new ShapeRenderer();
pb = new PolygonSpriteBatch();
assets = new AssetManager();
@ -62,9 +64,10 @@ public class BrickBuster extends Game {
public void resize(int width, int height) {
viewport.update(width, height);
sb.setProjectionMatrix(cam.combined);
sr.setProjectionMatrix(cam.combined);
pb.setProjectionMatrix(cam.combined);
Matrix4 projection = cam.combined.cpy().scl(PlayState.PIXEL_PER_METER);
sb.setProjectionMatrix(projection);
fb.setProjectionMatrix(cam.combined);
sr.setProjectionMatrix(projection);
super.resize(width, height);
}