vito-Z80

PixMap

Jul 12th, 2017
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package com.mygdx.game;
  2.  
  3. import com.badlogic.gdx.ApplicationAdapter;
  4. import com.badlogic.gdx.Gdx;
  5. import com.badlogic.gdx.graphics.Color;
  6. import com.badlogic.gdx.graphics.GL20;
  7. import com.badlogic.gdx.graphics.Pixmap;
  8. import com.badlogic.gdx.graphics.Texture;
  9. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  10. import com.badlogic.gdx.math.Vector2;
  11.  
  12. public class MyGdxGame extends ApplicationAdapter {
  13.  
  14.     private Vector2 touch;
  15.     private Vector2 preTouch;
  16.     private Pixmap pixmap;
  17.     private SpriteBatch batch;
  18.     private Texture img;
  19.     private int radius;
  20.  
  21.     @Override
  22.     public void create() {
  23.         touch = new Vector2();
  24.         preTouch = new Vector2();
  25.         pixmap = new Pixmap(800, 800, Pixmap.Format.RGBA8888);
  26.         pixmap.setColor(Color.ORANGE);
  27.         pixmap.drawCircle(300, 300, 30);
  28.         pixmap.fillCircle(100, 100, 50);
  29.         batch = new SpriteBatch();
  30.         img = new Texture(pixmap);
  31.         radius = 8;
  32.     }
  33.  
  34.     @Override
  35.     public void render() {
  36.         update();
  37.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  38.         batch.begin();
  39.         batch.draw(img, 0, 0);
  40.         img.draw(pixmap, 0, 0);
  41.         batch.end();
  42.     }
  43.  
  44.     private void update() {
  45.         getTouch();
  46.         draw();
  47.     }
  48.  
  49.     private void draw() {
  50.         if (touch.x < 0) return;
  51.         pixmap.fillCircle((int) touch.x, (int) touch.y, radius);
  52.     }
  53.  
  54.     public Vector2 getTouch() {
  55.         preTouch.set(touch);
  56.         if (Gdx.input.isTouched())
  57.             touch.set(Gdx.input.getX(), Gdx.input.getY());
  58.         else touch.set(-1000, -1000);
  59.         return touch;
  60.     }
  61.  
  62.     @Override
  63.     public void dispose() {
  64.         batch.dispose();
  65.         img.dispose();
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment