Android, Java & 2d Drawing -
been trying draw onto android view outside ondraw(canvas canvas) method.
@overrides public void ondraw(canvas canvas) { c = canvas; canvas.drawline(0, 50, 100, 50, paint); invalidate(); }
i want keep above displayed, while drawing character onto screen - depending on xposition , yposition.
public void drawplayer(int x, int y){ c.drawcircle(x, y, 5, paint); }
i'm pretty new 2d graphics in java & android.
thanks in advance
you need follow pattern this:
private boolean isplayervisible = false; private int playerposx; private int playerposy; @overrides public void ondraw(canvas canvas) { c = canvas; canvas.drawline(0, 50, 100, 50, paint); if (isplayervisible) { paint paint= new paint(); paint.setcolor(0xffffffff); paint.setstrokewidth(1); c.drawcircle(playerposx, playerposy, 5, paint); } } private void setplayerspos(int x, int y) { playerposx = x; playerposy = y; isplayervisible= true; invalidate(); }
all drawing happens in ondraw method. ondraw called whenever needed. can force ondraw run calling invalidate in method. meaningless call invalidate in ondraw method (perhaps cause unstable behavior, ondraw need run again after had finished executing).
Comments
Post a Comment