I am trying to get a simple animation of images. I want it to look like the rotor blades of a helicopter are turning. I have 3 images for a helicopter, and I show one of these images depending on the progress of the animation. the problem is that all three images ultimately overlap, not just one image displayed at a time, thus creating an animation. this is what i have done so far, I even tried to clear the canvas by doing this canvas.drawColor (Color.BLACK), but it will clear the whole canvas that I don't want.
this is what i have:
1) in the View class:
static class Helicopter {private long mLastUpdate; private long mProgress = 0; private final floating mX; closed final swimming mY;
private final Bitmap mHelicopter1;
private final Bitmap mHelicopter2;
private final Bitmap mHelicopter3;
private final float mRadius;
Helicopter(long mLastUpdate, float mX, float mY,
Bitmap helicopter1, Bitmap helicopter2, Bitmap helicopter3) {
this.mLastUpdate = mLastUpdate;
this.mX = mX;
this.mY = mY;
this.mHelicopter1 = helicopter1;
this.mHelicopter2 = helicopter2;
this.mHelicopter3 = helicopter3;
mRadius = ((float) mHelicopter1.getWidth()) / 2f;
}
public void update(long now) {
mProgress += (now - mLastUpdate);
if(mProgress >= 400L)
{
mProgress = 0;
}
mLastUpdate = now;
}
public void setNow(long now) {
mLastUpdate = now;
}
public void draw(Canvas canvas, Paint paint)
{
if (mProgress < 150L)
{
canvas.drawBitmap(mHelicopter1, mX - mRadius, mY - mRadius, paint);
}
else if (mProgress < 300L)
{
canvas.drawBitmap(mHelicopter2, mX - mRadius, mY - mRadius, paint);
}
else if(mProgress < 400L)
{
canvas.drawBitmap(mHelicopter3, mX - mRadius, mY - mRadius, paint);
}
}
public boolean done() {
return mProgress > 700L;
}
}
private ArrayList<Helicopter> mHelicopters = new ArrayList<Helicopter>();
2) run() :
private void doDraw(Canvas canvas)
{
final long now = SystemClock.elapsedRealtime();
canvas.save();
for (int i = 0; i < mHelicopters.size(); i++) {
final Helicopter explosion = mHelicopters.get(i);
explosion.update(now);
}
for (int i = 0; i < mHelicopters.size(); i++) {
final Helicopter explosion = mHelicopters.get(i);
explosion.draw(canvas, mPaint);
}
canvas.restore();
}
- ? , , , , . .