animation - How to animate a path on canvas - android -
is possible attach animator path? there other way draw on canvas animated lines? searched before post , there nothing this. in 2 other posts here , here there walk around solutions , not fit me. thank you!
i post code inside ondraw method specify want.
paint.setstyle(paint.style.stroke); paint.setstrokewidth(2); paint.setcolor(color.black); path path = new path(); path.moveto(10, 50); // transformations animated!!!!!!!! path.lineto(40, 50); path.moveto(40, 50); path.lineto(50, 40); // , on... canvas.drawpath(path, paint);
any ideas????
you can transform canvas time, i.e:
class myview extends view { int framespersecond = 60; long animationduration = 10000; // 10 seconds matrix matrix = new matrix(); // transformation matrix path path = new path(); // path paint paint = new paint(); // paint long starttime; public myview(context context) { super(context); // start animation: this.starttime = system.currenttimemillis(); this.postinvalidate(); } @override protected void ondraw(canvas canvas) { long elapsedtime = system.currenttimemillis() - starttime; matrix.postrotate(30 * elapsedtime/1000); // rotate 30° every second matrix.posttranslate(100 * elapsedtime/1000, 0); // move 100 pixels right // other transformations... canvas.concat(matrix); // call before drawing on canvas!! canvas.drawpath(path, paint); // draw on canvas if(elapsedtime < animationduration) this.postinvalidatedelayed( 1000 / framespersecond); } }
Comments
Post a Comment