clonebaby59
clonebaby59

Reputation: 187

canvas drawing Paint loop code

I'm drawing circles to the canvas every time I touch the screen. I add them to an arraylist of paths in the onTouch method. In my onDraw method, I loop through the array, drawing them.

When I try to change the paint of one of the circles, it changes them all. I don't want this, just want it to apply to one specific circle. How can I do that?

Code:

//on touch method
case MotionEvent.ACTION_DOWN:
    mode = Drag;
    x =(int) event.getX();
    y =(int) event.getY();
    path = new Path();
    path.addCircle(event.getX(), event.getY(), 8, Path.Direction.CCW);
    mpaint.setARGB(255, mcolor[0],100, mcolor[2]);
    circle.add(path);
    invalidate();

//on draw method
for (Path c : circle) {
    canvas.drawPath(c, mpaint);
}

Upvotes: 0

Views: 804

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234795

Two options:

  1. Store a separate Paint object along with each circle
  2. Query the Paint for the current values of whatever you are changing, and then restore them after drawing the circle.

Upvotes: 3

Related Questions