Advertisement
Guest User

Untitled

a guest
Oct 8th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 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.GL20;
  6. import com.badlogic.gdx.graphics.Pixmap;
  7. import com.badlogic.gdx.graphics.Texture;
  8. import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
  9. import com.badlogic.gdx.graphics.g2d.TextureRegion;
  10. import com.badlogic.gdx.scenes.scene2d.ui.Skin;
  11. import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
  12. import space.earlygrey.shapedrawer.ShapeDrawer;
  13. import space.earlygrey.shapedrawer.scene2d.ShapeDrawerDrawable;
  14.  
  15.  
  16. public class MyGdxGame extends ApplicationAdapter {
  17.     private Skin skin;
  18.     private Texture tmpTex;
  19.     private PolygonSpriteBatch batch;
  20.     private ShapeDrawer shape;
  21.     private float angle;
  22.  
  23.  
  24.     @Override
  25.     public void create () {
  26.  
  27.         /* Setting up the Stage. */
  28.         skin = new Skin(Gdx.files.internal("skin.json"));
  29.         batch = new PolygonSpriteBatch();
  30.  
  31.         /* Ideally, you would extract such a pixel from your Atlas instead. */
  32.         Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
  33.         pixmap.setColor(1,0,0,.5f);
  34.         pixmap.fill();
  35.         tmpTex = new Texture(pixmap);
  36.         pixmap.dispose();
  37.  
  38.         /* Setting up the ShapeDrawer. */
  39.         shape = new ShapeDrawer(batch, new TextureRegion(tmpTex));
  40.     }
  41.  
  42.  
  43.     @Override
  44.     public void render () {
  45.  
  46.         /* Clearing the screen and filling up the background. */
  47.         Gdx.gl.glClearColor(0,0,0, 1);
  48.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  49.  
  50.         angle += Gdx.graphics.getDeltaTime()/2;
  51.         final float RADIUS = 120;
  52.         Drawable drawable = new ShapeDrawerDrawable(shape){
  53.             @Override
  54.             public void drawShapes(ShapeDrawer shapeDrawer, float x, float y, float width, float height) {
  55.                 shapeDrawer.arc(Gdx.graphics.getWidth()/2f,
  56.                         Gdx.graphics.getHeight()/2f,
  57.                         RADIUS/2, angle, .8f, RADIUS);
  58.             }
  59.         };
  60.  
  61.         batch.begin();
  62.         drawable.draw(batch, Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f, RADIUS*2, RADIUS*2);
  63.         batch.end();
  64.     }
  65.  
  66.  
  67.     @Override
  68.     public void dispose () {
  69.  
  70.         /* Disposing is good practice! */
  71.         batch.dispose();
  72.         tmpTex.dispose();
  73.         skin.dispose();
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement