Advertisement
dermetfan

draw a ChainShape

Nov 26th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. Camera camera = new OrthographicCamera();
  2. InputAdapter paint = new InputAdapter() {
  3.  
  4.     private boolean drawing;
  5.     private FloatArray coords = new FloatArray();
  6.     private Vector3 tmp = new Vector3();
  7.  
  8.     @Override
  9.     public boolean keyTyped(char character) {
  10.         switch(character) {
  11.         case 'c':
  12.             if(drawing) // drawing was enabled, so this will disable it and create the ChainShape
  13.                 createChainShape();
  14.             drawing = !drawing; // toggle
  15.             return true;
  16.         default:
  17.             return false;
  18.         }
  19.     }
  20.  
  21.     @Override
  22.     public boolean touchDragged(int screenX, int screenY, int pointer) {
  23.         if(drawing) {
  24.             tmp.x = screenX;
  25.             tmp.y = screenY;
  26.             camera.unproject(tmp);
  27.             coords.add(tmp.x);
  28.             coords.add(tmp.y);
  29.             return true;
  30.         }
  31.         return false;
  32.     }
  33.  
  34.     public ChainShape createChainShape() {
  35.         ChainShape shape = new ChainShape();
  36.         coords.shrink(); // reduce inner array to make sure it's not longer than needed
  37.         shape.createChain(coords.items);
  38.         return shape;
  39.     }
  40.  
  41. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement