Friday, 15 April 2011

android - Canvas doesn't clear clean after drawPath, works fine with drawCircle -



android - Canvas doesn't clear clean after drawPath, works fine with drawCircle -

i'm trying draw various shapes. here's view's ondraw:

protected void ondraw(canvas canvas) { this.invalidate(); canvas.drawcolor(color.white); paint paint = new paint(); paint.setstyle(style.stroke); triangle.setfilltype(filltype.even_odd); triangle.moveto(shape.getx(), shape.gety()); triangle.lineto(shape.getx() - shape.getdiameter(), shape.gety() - shape.getdiameter()); triangle.lineto(shape.getx() + shape.getdiameter(), shape.gety() - shape.getdiameter()); triangle.lineto(shape.getx(), shape.gety()); triangle.close(); canvas.drawpath(triangle, paint); }

triangle path, shape class utilize hold coordinates of shapes draw on view. triangle's x , y coordinates alter dynamically, shape redrawn @ new position each turn.

but here looks like:

it's of import note there single triangle here, screen beingness inefficiently cleared on each loop.

the exact same code using drawcircle or drawrect instead of drawpath produces clean , clear canvas objects updated position.

i've figure out problem. when using path it's necessary reset on each draw (see line 8):

protected void ondraw(canvas canvas) { this.invalidate(); canvas.drawcolor(color.white); paint paint = new paint(); paint.setstyle(style.stroke); triangle.reset() // <------- add together triangle.setfilltype(filltype.even_odd); triangle.moveto(shape.getx(), shape.gety()); triangle.lineto(shape.getx() - shape.getdiameter(), shape.gety() - shape.getdiameter()); triangle.lineto(shape.getx() + shape.getdiameter(), shape.gety() - shape.getdiameter()); triangle.lineto(shape.getx(), shape.gety()); triangle.close(); canvas.drawpath(triangle, paint); }

android opengl-es path android-canvas shape

No comments:

Post a Comment