vnshetty
vnshetty

Reputation: 20132

Android animation not working properly

I used the following segment of code to animate a balloon. Here the balloon is nothing, but the button and it is animating using translate animation.

Animation works fine, but while balloon moving some white dots are displaying (See the Image ). Why? Any Solution?

See this Image:

enter image description here

            -------------
    anim = new TranslateAnimation(0, 360,1000,-100 );
    anim.setRepeatMode(Animation.REVERSE);
    anim.setRepeatCount(Animation.INFINITE);
    anim.setDuration(10000L);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());

    btnBalloon.setAnimation(anim);

Upvotes: 1

Views: 604

Answers (1)

fredley
fredley

Reputation: 33941

You are not clearing the canvas on each new frame. The dots are the edge of previous instances of the balloon that are still visible.

Each time the canvas is drawn, it does not start from scratch, it draws on top of what's already there. This means that each time the balloon is drawn, it's drawing on top of every other instance of it. I'm guessing your balloon image has a black background? To remedy this, you'll need to 'clear' your canvas, by drawing the background afresh, on each frame. In this case, you'll need to drawn a black rectangle that covers the whole frame, before drawing the balloon.

Upvotes: 2

Related Questions