Animation Issue when Reusing code Android -


i have application spawn new enemy every 4 seconds. enemy goes right left using antranslateanimation. animation takes 7 seconds total.

the problem i'm facing when animation running, every time spawn new enemy, animation stops old 1 , starts animating new enemy.

is there way animate 2 different objects using same translateanimation?

just in case, here animation

        translate= new translateanimation(             animation.absolute, (float) 1.0,             animation.absolute, (float) -4.0,             animation.absolute,0,             animation.absolute,0);      translate.setduration(10000);     translate.setfillafter(true);     //newiv enemy's imageview     newiv.startanimation(translate); 

you can apply animation this

make animation xml in anim folder

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"      android:shareinterpolator="false">      <translate         android:fromxdelta="100%" android:toxdelta="0%"         android:fromydelta="0%" android:toydelta="0%"         android:duration="500"          />    </set> 

then code in class

final animation righttoleft = animationutils.loadanimation(context,                 r.anim.right_to_left);           ((imageview)findviewbyid(r.id.yourimage))                 .startanimation(righttoleft); 

hope help.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -