Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestPixMap implements Screen {
- private float upp;
- private float pmWidth; // ширина пиксмапа
- private float pmHeight; // высота пиксмапа
- private float pmXinScreen; // координат X расположения пиксмапа на экране
- private float pmYinScreen; // координат Y расположения пиксмапа на экране
- private int pmSize; // размер пиксмапа на экране (width & height)
- private float screenWidth;
- private float screenHeight;
- private Vector2 screenClick;
- private Vector2 pmClick;
- private Pixmap pixmap;
- private Texture texture;
- private SpriteBatch batch;
- @Override
- public void show() {
- screenClick = new Vector2();
- pmClick = new Vector2();
- batch = new SpriteBatch();
- screenWidth = Gdx.graphics.getWidth();
- screenHeight = Gdx.graphics.getHeight();
- pmWidth = 256;
- pmHeight = 256;
- pmXinScreen = 194;
- pmYinScreen = 206;
- pmSize = 111;
- pixmap = new Pixmap((int) pmWidth, (int) pmHeight, Pixmap.Format.RGBA8888);
- pixmap.setColor(Color.ORANGE);
- pixmap.fill();
- texture = new Texture(pixmap);
- }
- @Override
- public void render(float delta) {
- Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
- update();
- batch.begin();
- batch.draw(texture, pmXinScreen, pmYinScreen, pmSize, pmSize);
- batch.end();
- }
- private void update() {
- upp = screenWidth < screenHeight ? pmWidth / pmSize : pmHeight / pmSize;
- listener();
- drawInPm();
- }
- private void drawInPm() {
- pixmap.setColor(Color.GREEN);
- pixmap.fillCircle((int) pmClick.x, (int) pmClick.y, 4);
- texture.draw(pixmap, 0, 0);
- }
- private void listener() {
- float screenX = Gdx.input.getX();
- float screenY = screenHeight - Gdx.input.getY();
- screenClick.set(screenX, screenY);
- float pmX = (screenX - pmXinScreen) * upp;
- float pmY = pmHeight - (screenY - pmYinScreen) * upp;
- pmClick.set(pmX, pmY);
- System.out.print(upp);
- System.out.println(pmClick);
- }
- @Override
- public void resize(int width, int height) {
- }
- @Override
- public void pause() {
- }
- @Override
- public void resume() {
- }
- @Override
- public void hide() {
- }
- @Override
- public void dispose() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment