java - Moving objects on path -


i'd create moving arrows on path, this:

moving arrows

how done?

edit:

i've succcessfully created these moving arrows way: i've divided path same parts , in beginning of each part i've placed arrow. positions of arrows periodically updated , when @ end, set position start.

moving arrow i've implemented using this example of moving object along path. problem i'd have arrow in middle of path, not on or under it. how done?

this ondraw method:

@override protected void ondraw(canvas canvas) {     canvas.drawbitmap(bmbackground, rsrc, rdest, null);     canvas.drawpath(ptcurve, paint);     //animate sprite     matrix mxtransform = new matrix();     if (icurstep <= imaxanimationstep) {         pm.getmatrix(fsegmentlen * icurstep, mxtransform,                 pathmeasure.position_matrix_flag + pathmeasure.tangent_matrix_flag);         mxtransform.pretranslate(-bmsprite.getwidth(), -bmsprite.getheight());         canvas.drawbitmap(bmsprite, mxtransform, null);          icurstep++; //advance next step         invalidate();     } else {         icurstep = 0;     } } 

where pm pathmeasure.

i'll give data classes. need use them draw.

you'll want position class hold place of arrow , it'll used path. should provide access x , y of double type specific storage, cast int type screen position.

next, you'll have path class. it'll have arraylist<position> contain path. can use these points draw lines path in graphics method.

then, you'll have arrow class. i'd suggest giving position not type position if double. additionally should have field speed. @ each update add speed position.

for drawing purposes still need place , direction of arrow. this'll take class vector has fields position position , double angle. you'll need method in path , public vector getvectorat(double pos). method should take position attribute of arrow , return vector arrow , pointing. can use return draw it.

i plan on attempting when chance, maybe i'll update later source.


as setting arrow in center of line try:

mxtransform.pretranslate(-bmsprite.getwidth()/2, -bmsprite.getheight()/2); 

instead of line have using matrix.pretranslate(...). can't emulate have without entire user class(es), may not work.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -