animation - Android onDraw loop -
i've set global variables x,y in activity class.
i start thread "t0" continually update globals x , y.
i have ondraw pseudocode follows (all on ui thread):-
view.ondraw(){ if (x,y changed value) { x0=x; y0=y; loop (x0-- until x0==0){ canvas.drawbitmap(bmp, x0, y0, bitmappaint); invalidate(); } } }
i hoping i'd see animation of bitmap moving across screen on x-axis, each invalidate() re-drawing new position. instead see 'jump' last x position 0 (no intermediate stages).
i'm making assumption although x , y updating via t0, i'm not concerned since loop busy original x,y values (assigned x0,y0).
i observe x,y updating , code executed inside 'if loop' (i see via debug).
i tried adding delay, didn't seem make difference. can re-draw directly new x,y position, need smooth 'transition' via loop happen one-x0-coord another.
any hints or tips appreciated.
thanks in advance.
steve
i think can't cause ondraw
within ondraw
. calling invalidate()
causes ondraw
called after current ondraw
finishes. not sure how implemented since it's pseudocode imagine don't want loop in ondraw somethinglike this:
view.ondraw(){ if (x,y changed value) { x0=x; y0=y; if (x0!=0){ x0--; canvas.drawbitmap(bmp, x0, y0, bitmappaint); invalidate(); } } }
Comments
Post a Comment