Animation Problem


Last Updated:

  1. DiscGolfer17

    DiscGolfer17 Member This Topic's Starter

    Joined:
    Jul 29, 2010
    Messages:
    18
    Likes Received:
    1
    I have a bubble breaker game that I am trying to add simple animations to. When the user selects the objects to remove, I then call two methods... performSlideDownAnimation() and performSlideRightAnimation(). The slide right doesn't get called unless there is an empty column. All the animations are fine until there is an empty column. When slide right gets called it tries to perform an animation on a view that is still performing the slide down animation. Therefore the slide down animation is getting killed and the slide right takes over. This leaves me with unfinished animations.

    My question is if there is anyway to call the second method after ALL the animations from the first method are finished. I have tried using animation listener but the problem with that is that the animation set is created every time through a loop.

    my two methods....

    private void performSlideDownAnimation() {
    int spaces = 0;

    for(int i=0; i<numCols; i++) { // column loop
    for(int j=numRows-1; j>=0; j--) { // row loop
    try {
    if(circles[j] == null && circles[j-1] != null) {
    AnimationSet animation = new AnimationSet(true);

    spaces = getSpacesToMoveDown(i, j);

    TranslateAnimation translate = new TranslateAnimation(
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f,
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, (radius*2)*spaces
    );
    translate.setDuration(ANIMATION_DURATION/2);
    translate.setZAdjustment(Animation.ZORDER_TOP);

    animation.addAnimation(translate);
    animation.setInterpolator(this, android.R.anim.linear_interpolator);
    animation.setFillAfter(true);
    animation.setStartOffset(ANIMATION_DURATION/2);

    circles[j-1].setAnimation(animation);

    circles[j+(spaces-1)] = circles[j-1];
    circles[j-1] = null;
    }
    } catch(ArrayIndexOutOfBoundsException e) {}
    } // end row
    } // end column
    }

    private void performNormalSlideRightAnimation() {
    int spaces = getSpacesToMoveRight();
    for(int i=0; i<moveColumn; i++) { // column loop
    for(int j=0; j<numRows; j++) { // row loop
    try {
    if(circles[j] == null) {
    continue;
    }
    else {
    AnimationSet animation = new AnimationSet(true);

    TranslateAnimation translate = new TranslateAnimation(
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, (radius*2)*spaces,
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f
    );
    translate.setDuration(125);
    translate.setZAdjustment(Animation.ZORDER_TOP);

    animation.addAnimation(translate);
    animation.setInterpolator(this, android.R.anim.linear_interpolator);
    animation.setFillAfter(true);
    animation.setStartOffset(ANIMATION_DURATION/2);

    circles[j].setAnimation(animation);
    }
    } catch(ArrayIndexOutOfBoundsException e) {}
    } // end row
    } // end column
    }
     

    Advertisement

Share This Page

Loading...