1 package ru
.deadsoftware
.cavecraft
.misc
;
3 import com
.badlogic
.gdx
.graphics
.OrthographicCamera
;
4 import com
.badlogic
.gdx
.graphics
.g2d
.SpriteBatch
;
5 import com
.badlogic
.gdx
.graphics
.g2d
.SpriteCache
;
6 import com
.badlogic
.gdx
.graphics
.glutils
.ShapeRenderer
;
7 import ru
.deadsoftware
.cavecraft
.GameScreen
;
9 public abstract class Renderer
{
11 private OrthographicCamera camera
;
13 protected ShapeRenderer shaper
;
14 protected SpriteBatch spriter
;
15 protected SpriteCache spriteCache
;
18 this(GameScreen
.getWidth(), GameScreen
.getHeight());
21 public Renderer(float width
, float height
) {
22 camera
= new OrthographicCamera();
23 camera
.setToOrtho(true, width
, height
);
24 shaper
= new ShapeRenderer();
25 shaper
.setProjectionMatrix(camera
.combined
);
26 spriter
= new SpriteBatch();
27 spriter
.setProjectionMatrix(camera
.combined
);
28 spriteCache
= new SpriteCache();
29 spriteCache
.setProjectionMatrix(camera
.combined
);
32 public float getWidth() {
33 return camera
.viewportWidth
;
36 public float getHeight() {
37 return camera
.viewportHeight
;
40 public float getCamX() {
41 return camera
.position
.x
;
44 public float getCamY() {
45 return camera
.position
.y
;
48 public void setCamPos(float x
, float y
) {
49 camera
.position
.set(x
, y
, 0);
52 public void setFontScale(float scale
) {
53 Assets
.mcFont
.getData().setScale(scale
);
56 protected void setFontColor(int r
, int g
, int b
) {
57 Assets
.mcFont
.setColor(r
/ 255f, g
/ 255f, b
/ 255f, 1f);
60 protected void drawString(String str
, float x
, float y
) {
61 Assets
.mcFont
.draw(spriter
, str
, x
, y
);
64 protected void drawString(String str
) {
65 Assets
.mcFont
.draw(spriter
, str
,
66 getWidth() / 2 - (float) Assets
.getStringWidth(str
) / 2,
67 getHeight() / 2 - (float) Assets
.getStringHeight(str
) / 2);
70 public abstract void render();