Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Camera camera = new OrthographicCamera();
- InputAdapter paint = new InputAdapter() {
- private boolean drawing;
- private FloatArray coords = new FloatArray();
- private Vector3 tmp = new Vector3();
- @Override
- public boolean keyTyped(char character) {
- switch(character) {
- case 'c':
- if(drawing) // drawing was enabled, so this will disable it and create the ChainShape
- createChainShape();
- drawing = !drawing; // toggle
- return true;
- default:
- return false;
- }
- }
- @Override
- public boolean touchDragged(int screenX, int screenY, int pointer) {
- if(drawing) {
- tmp.x = screenX;
- tmp.y = screenY;
- camera.unproject(tmp);
- coords.add(tmp.x);
- coords.add(tmp.y);
- return true;
- }
- return false;
- }
- public ChainShape createChainShape() {
- ChainShape shape = new ChainShape();
- coords.shrink(); // reduce inner array to make sure it's not longer than needed
- shape.createChain(coords.items);
- return shape;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement