Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package lib; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Buttons; import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; /** * ?? fxf * * @author mypc */ public class Game extends ApplicationAdapter { /** * */ OrthographicCamera camera; /** * ? ? , ? * */ static Camera currentCamera; /** * Batch ? ?? */ SpriteBatch batch; /** * ?-? ?. ? - Batch */ Graphics2D ctx; /** * ? ?? */ @Override public void create() { camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0); camera.update(); currentCamera = camera; batch = new SpriteBatch(); ctx = new lib.Graphics2D(batch); this.initResources(); } /** * ? ?? */ public void initResources() { } /** * ?? * * @param elapsedTime ?, ? ? */ public void update(long elapsedTime) { } /** * */ @Override public void render() { camera.update(); Gdx.gl.glClearColor(1, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); update((long) (Gdx.graphics.getDeltaTime() * 1000.0)); ctx.getBatch().setProjectionMatrix(camera.combined); ctx.begin(); ctx.batch.setColor(Color.WHITE); renderInContext(ctx); ctx.end(); } /** * ? ??? * * @param g ? */ public void renderInContext(lib.Graphics2D g) { } /** * ? ?? */ @Override public void dispose() { TextureManager.disposeTextures(); } /** * X ? * * @return X ? */ public int getMouseX() { return Gdx.input.getX() - Gdx.graphics.getWidth() / 2; } /** * Y ? * * @return Y ? */ public int getMouseY() { return (Gdx.graphics.getHeight() / 2 - Gdx.input.getY()); } /** * * * @return */ public int getWidth() { return (Gdx.graphics.getWidth()); } /** * ? * * @return */ public int getHeight() { return (Gdx.graphics.getHeight()); } /** * ? * * @param key - * @return - ? */ public boolean keyPressed(int key) { if (key == 32) // SPACE return Gdx.input.isKeyPressed(62); return false; } /** * ? * * @return - ? */ public boolean click() { return Gdx.input.isButtonPressed(Buttons.LEFT); } }