All- I have a simple app in which I want a man to walk across the screen. Right now the animation is happening in one place like a sticky note flip book. In other words the frames are changing in one place like a spinning wheel would. My question is how can I get the animation to progress forward (at my desired pace) as well as change frames? Here is my code concerning this issue:
public void start(View v) {
ImageView img = (ImageView)findViewById(R.id.imageView);
img.setBackgroundResource(R.drawable.animation);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();
}
Thanks for your time and effort!
You could do something like this, using your own image(the image of the man):
Main Class:
Animation Class:
XML file:
In fact, if you want you can go ahead and copy paste my code and see how it works(make sure to put an image in the drawable-hdpi folder)… you should be able to use it as a template for your project. Hope it helps!
P.S You could of course, change the
ChangingYvariable toChangingX(for example; of course you would have to change a couple other things like thedrawBitmap()method.. not hard though) to make the ball move in a horizontal line… see how it works out for you.