Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mygdx.game;
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.Pixmap;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.math.Vector2;
- public class MyGdxGame extends ApplicationAdapter {
- private Vector2 touch;
- private Vector2 preTouch;
- private Pixmap pixmap;
- private SpriteBatch batch;
- private Texture img;
- private int radius;
- @Override
- public void create() {
- touch = new Vector2();
- preTouch = new Vector2();
- pixmap = new Pixmap(800, 800, Pixmap.Format.RGBA8888);
- pixmap.setColor(Color.ORANGE);
- pixmap.drawCircle(300, 300, 30);
- pixmap.fillCircle(100, 100, 50);
- batch = new SpriteBatch();
- img = new Texture(pixmap);
- radius = 8;
- }
- @Override
- public void render() {
- update();
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- batch.begin();
- batch.draw(img, 0, 0);
- img.draw(pixmap, 0, 0);
- batch.end();
- }
- private void update() {
- getTouch();
- draw();
- }
- private void draw() {
- if (touch.x < 0) return;
- pixmap.fillCircle((int) touch.x, (int) touch.y, radius);
- }
- public Vector2 getTouch() {
- preTouch.set(touch);
- if (Gdx.input.isTouched())
- touch.set(Gdx.input.getX(), Gdx.input.getY());
- else touch.set(-1000, -1000);
- return touch;
- }
- @Override
- public void dispose() {
- batch.dispose();
- img.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment