java - android view animaiton on a path -


i trying make 2d animation , want image go on brown path in ground. using valueanimator this,

that image

here code first part of animation:

anim = valueanimator.offloat(0f,400f);     anim.setduration(500);     anim.addupdatelistener(new valueanimator.animatorupdatelistener()     {         @override         public void onanimationupdate(valueanimator animation)         {             value = (float)animation.getanimatedvalue();              if(soldier.getx()<400f)                 soldier.setx(value);         }     }); 

when done setting image's x value cant figure out efficient way start making change y go , x,y , x again.. thanks.

update: code helped me make path animation down here.
tried make ratio formula between emulator's screen dimension , other phone:

metrics = new displaymetrics();   //get screen dimensions     getwindowmanager().getdefaultdisplay().getmetrics(metrics);      heightpixels = metrics.heightpixels; //initiate screen dimensions     widthpixels = metrics.widthpixels;      ratiox = heightpixels/1080;//set ratios     ratioy = widthpixels/1794;      path path = new path();     path.moveto(-100*ratiox,800*ratioy);     path.lineto(430*ratiox, 800*ratioy);     path.lineto(430*ratiox,180*ratioy);     path.lineto(1145*ratiox,180*ratioy);     path.lineto(1145*ratiox,800*ratioy);     path.lineto(1794*ratiox,800*ratioy);       anim = objectanimator.offloat(soldier,"x","y",path);     anim.setduration(3500); 

this worked fine on emulator, doesnt work on phone(the animation stops in middle , doesnt follow background's path.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -