Libgdx rounds



  • There are three circles, each round is divided into three parts where colour is given, each circle shall be rotated in different directions. How do you do that?

    картинка



  • My answer isn't for libgdx, it's just Android. But someone might be interested.

    It's a caste show:

    public class ProgressView extends View {
    private Paint paint;
    private float mProgress;
    private final RectF oval = new RectF();
    

    public ProgressView(Context context) {
    super(context);
    initPaint();
    }

    public void setProgress(final float progress) {
    if (progress == mProgress) {
    return;
    }
    mProgress = progress;
    invalidate();
    }

    private void initPaint() {
    paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float width = (float)getWidth();
    float height = (float)getHeight();
    float radius;
    if (width > height){
        radius = height/4;
    }
    else{
        radius = width/4;
    }
    float center_x, center_y;
    
    center_x = width/2;
    center_y = height/2;
    
    oval.set(center_x - radius, center_y - radius, center_x + radius, center_y + radius);
    int initialAngle = (int)(mProgress / 100 * 360);
    drawCircle(canvas, oval, 15, initialAngle);
    
    oval.set(center_x - 2*radius/3, center_y - 2*radius/3, center_x + 2*radius/3, center_y + 2*radius/3);
    initialAngle = -initialAngle;
    drawCircle(canvas, oval, 10, initialAngle);
    
    oval.set(center_x - radius/3, center_y - radius/3, center_x + radius/3, center_y + radius/3);
    initialAngle = -initialAngle;
    drawCircle(canvas, oval, 5, initialAngle);
    

    }

    private void drawCircle(Canvas canvas, RectF rectF, int strokeWidth, int initAngle) {
    paint.setStrokeWidth(strokeWidth);

    paint.setColor(Color.RED);
    canvas.drawArc(rectF, initAngle, 120, false, paint);
    
    paint.setColor(Color.YELLOW);
    canvas.drawArc(rectF, initAngle + 120, 120, false, paint);
    
    paint.setColor(Color.WHITE);
    canvas.drawArc(rectF, initAngle + 240, 120, false, paint);
    
    }
    

    }

    This is an activity using this View, where movement to different sides is achieved by ValueAnimator:

    public class MainActivity extends AppCompatActivity {
    private ProgressView progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    progressBar = new ProgressView(this);
    setContentView(progressBar);
    
    
    ValueAnimator anim = ValueAnimator.ofInt(0, 1000);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            progressBar.setProgress((int)animation.getAnimatedValue());
        }
    });
    anim.setDuration(40000);
    anim.setRepeatCount(ValueAnimator.INFINITE);
    anim.start();
    }
    

    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2