views:

97

answers:

1

I am trying to show an animation on a canvas when user touches to the screen.I know basics and how to draw a bitmap on to canvas but i couldn't find anything good on drawing or showing animation on canvas.i will use frame by frame animation and it will appear at the same position user touched that is why i can't use ImageView.

+2  A: 

Not sure if there is a built-in way of doing this. But it's fairly straightforward to simply load the bitmaps into an array.

Then call invalidate(), your onDraw() method should invalidate() itself and on the next run calculate which frame to display (by calculating the time the last frame was displayed). Every time you play a frame you increase the frame counter and reset the time counter.

You can use a variable delay, and it's fairly easy to implement.

Miguel Morales
Thanks for your answer.I tried this one before asking this question but there is a problem when i call invalidate() from a for loop it just invalidates onces and it shows the first frame on the screen .
Tony
You have to then call invalidate() or postInvalidate() WITHING your onDraw() method to have it be recalled.
Miguel Morales
Thank you very much.you saved my life.
Tony