Wednesday 15 January 2014

java - Custom curved lines in Android -



java - Custom curved lines in Android -

i working on game have bezier curves. @ moment, fine , it's working should, although complicated operation on curves. draw curves utilize canvas , paths, this:

private void refresh() { mpath = new path(); mpath.moveto(start_x, start_y); mpath.cubicto(anchor1_x, anchor1_y, anchor2_x, anchor2_y, end_x, end_y); } public void draw(canvas canvas, paint paint) { path newpath = new path(mpath); matrix mmatrix = new matrix(); mmatrix.settranslate(-mcamera.x1, -.mcamera.y1); mmatrix.postscale(mcamera.getwidthratio(), mcamera.getheightratio()); newpath.transform(mmatrix); canvas.drawpath(newpath, paint); }

the paint parameter ussually next one:

curvespaint = new paint(); curvespaint.setcolor(0xffffffff); curvespaint.setantialias(true); curvespaint.setstrokecap(paint.cap.round); curvespaint.setstrokejoin(paint.join.round); curvespaint.setstyle(paint.style.stroke); curvespaint.setstrokewidth(canvas.getheight() / 100f); if (shadow) curvespaint.setshadowlayer(canvas.getheight() / 50f, 0, 0, 0xaaffffff); else curvespaint.setshadowlayer(0, 0, 0, 0xaaffffff);

my question is: how can create curves more beautiful? @ moment, they're white (or white white shadow). want able draw them nice gradient or model on them , have no thought how that. thinking setshader function of paint class don't know if can utilize purpose or how utilize it. other solutions, drawing multiple paths 1 above other, impractical due low fps.

i suggest start looking @ using opengl or third-party wrapper libraries such libgdx. canvas meant relatively simple graphics. don't think takes advantage of devices gpu. take advantage of total powerfulness of gpu, need utilize opengl.

java android canvas shader bezier

No comments:

Post a Comment