I am relatively new to animation in android and just getting the feel of a couple of things.I want to know how i can make a “man”(image) run on android.The man is an icon.IF i use animation through the following code the icon just moves across the screen.How do i get the running motion.
public anima1(Context context)
{
super(context);
cloud=BitmapFactory.decodeResource(getResources(),R.drawable.androidicon);
// TODO Auto-generated constructor stub
}
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Rect re=new Rect();
re.set(0,0,canvas.getWidth(),canvas.getHeight());
Paint c=new Paint();
c.setColor(Color.WHITE);
c.setStyle(Paint.Style.FILL);
canvas.drawRect(re,c);
x=x+10;
if(x==canvas.getWidth())
{
y=y+10;
x=0;
}
if(y==canvas.getHeight())
{
x=0;
y=0;
}
canvas.drawBitmap(cloud, x, y,p);
invalidate();
}
To make the man appear to run, you should have several different images of the man with his feet in different positions and swap out the image on every loop. Alternatively, you could use an animated GIF, but I am not sure whether Android will actually play the animation.