Animating a imageview on a random path in Android
The task seems fairly simple but I don't know what's the best way to implement it in Android.
How it should look
There should be a number of images on the screen (let's say 4-5 max) each image will have as a Background a FrameAnimation that's oneTime(false) (representing a running man). Each of these images need to have a random path to follow around the screen, calculated when it's first created. So the running man will go around the screen in different directions. Each image will have a onClick listener so when clicked on it, it will be removed from the screen.
What is the best way to do this in Android starting with 1.6 without causing performance drops or Bitmap Memory leaks ?
I attach a image for exemplification. Thank you all for your time.开发者_运维百科
Later Edit: the best solution seems to use a extended SurfaceView. I saw some samples with adding, moving the image around, but I don't know yet how could I intercept the onTouchEvent. I can override the onTouchEvent of the surfaceView. The solution that comes now in my mind is get x and y of the touched spot and then look in the animated images if any is under the x,y pressed spot. This seems pretty complicate.
Each running sprite will have its rectangle cooridantes; top-left and bottom right. All you need to do is to loop through your sprites and see if the user has touched a point where x and y are within a sprite's rectangle.
However you will have to synchronize{} some blocks of code as well...
精彩评论