-2

i am trying to implement an animated butterfly which should fly around the screen by clicking a button .How can i implement it efficiently.If i need multiple butterflies(may be 100+) whether it effect device performance?.How can i achieve fly effect on wings.

  1. Is it possible to implement with many parts of a butterfly image put together and bring this fly effect.
  2. Can i use renderScript

Please provide a sample code.i tried scaled animation but it is not as expected .any help appreciable.

Askarc Ali
  • 318
  • 4
  • 21

1 Answers1

0

You can achieve a quite good performance with showing a simple gif in your layout. Just create a gif out of the images you have (use some gif maker for that - there are a ton of other options, just search for it). For showing the gif in your application you can use a custom library, like android-gif-drawable. Implementation is similar to an ImageView:

<pl.droidsonroids.gif.GifImageView
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:src="@drawable/your_butterfly_anim"
/>

It's a possibility for simple animations.

Edit:

int distance = 100; //the distance to move in pixels
int duration = 500; //the duration of the animation in ms

double direction = Math.random() * 2 * Math.PI;

int translationX = Math.cos(direction) * distance;
int translationY = Math.sin(direction) * distance;

yourImageView.animate().translationX(translationX).translationY(translationY).setDuration(duration).start();

This should give you some first ideas of how you can get it flying randomly.

dabo248
  • 3,367
  • 4
  • 27
  • 37