2011-01-11 14 views
1

私はゲームアプリケーションを作成しています。ユーザーが間違ったボタンを押した場合、私はアニメーションを表示したい。アニメーションが完了したら、ゲームを終了する。Androidがアクティビティが終了する前にアニメーションが終了するのを待ちます。

現在のところ、私のアニメーションは仕上げが呼び出されたときに始まります。私はアニメーションを完成させたい。以下は

AnimationListener

public final class DisplayNextView implements Animation.AnimationListener { 
    View changeView; 
    Drawable image; 

    public DisplayNextView(View parChangeView, Drawable parImage) { 
     this.changeView = parChangeView; 
     this.image = parImage; 
    } 

    public void onAnimationStart(Animation animation) { 
     changeView.post(new SwapViews(changeView, image)); 
     changeView.postDelayed(new SwapViews(changeView, null), 1000); 
    } 

    public void onAnimationEnd(Animation animation) { 

    } 

    public void onAnimationRepeat(Animation animation) { 

    } 
} 

これはこれはこれはスレッド

public final class SwapViews implements Runnable { 
    View changeView; 
    Drawable image; 

    public SwapViews(View parChangeView, Drawable parImage) { 
     this.changeView = parChangeView; 
     this.image = parImage; 
    } 

    public void run() { 
     final float centerX = changeView.getWidth()/2.0f; 
     final float centerY = changeView.getHeight()/2.0f; 
     Flip3DAnimation rotation; 
     changeView.setBackgroundDrawable(image); 
     //TODO should find a better way!! 
     if (image==null) 
      changeView.setBackgroundColor(Color.BLACK); 


     rotation = new Flip3DAnimation(-90, 0, centerX, centerY); 


     rotation.setDuration(250); 
     rotation.setFillAfter(true); 
     rotation.setInterpolator(new DecelerateInterpolator()); 

     changeView.startAnimation(rotation); 

    } 
} 
である私のSwapViewクラスでアニメーション

private void applyRotation(View parChangeView, Drawable image, float start, float end) { 
     // Find the center of image 
     final float centerX = parChangeView.getWidth()/2.0f; 
     final float centerY = parChangeView.getHeight()/2.0f; 

     // Create a new 3D rotation with the supplied parameter 
     // The animation listener is used to trigger the next animation 
     final Flip3DAnimation rotation = 
       new Flip3DAnimation(start, end, centerX, centerY); 
     rotation.setDuration(250); 
     rotation.setFillAfter(true); 
     rotation.setInterpolator(new AccelerateInterpolator()); 
     rotation.setAnimationListener(new DisplayNextView (parChangeView,image)); 
     parChangeView.startAnimation(rotation); 
     //return rotation; 
     } 

を開始し、私の主な活動方法であるが実装私のクラスであります

答えて

0

あなたはこの「アニメーション」とは何かを具体的に表現できますか?自分でフレームを再生したり、画像やビデオだけを再生するクラスですか?

これが最初の最良の方法であれば、コールバックメソッドを作成し、アニメーションが完了した時点でそれを起動することです。このような

+0

私は私の主な活動からアニメーションを始めています。私は、アニメーションとアニメーションのリスナーのためのカスタムクラスを使用しています。アニメーションについては、例をhttp://www.inter-fuser.com/2009/08/android-animations-3d-flip.htmlから変更しました。アニメーションはイメージです。 ユーザーがボタンをクリックし、「回答」が間違っていると、結果が間違っていることを示すためにカードが反転し、その後、アクティビティを終了します。しかし、私の活動はアニメーションが完了する前に終了します。また、ユーザーが右ボタンをクリックすると、正しい結果を示すカードと同じアニメーションが表示されます。 – SingleMalt

+0

アニメーションリスナーを使用しているとします。 AnimationListenerのonAnimationEnd()コールバックを使用していますか?私は何をしているのかを正確に見るためにいくつかのサンプルコードが必要です。あなたの応答とすべての助けを感謝して=/ – Nick

+0

を推測するのは難しいです。私は自分の質問を更新し、コードに追加しました。あなたが何か他のものが必要な場合は教えてください。 – SingleMalt

0

何か:

public final class DisplayNextView implements Animation.AnimationListener { 
View changeView; 
Drawable image; 
boolean mIsCorrect; 
Activity mContext; 

public DisplayNextView(View parChangeView, Drawable parImage, 
     boolean isCorrect, Activity context) { 
    this.changeView = parChangeView; 
    this.image = parImage; 
    mIsCorrect = isCorrect; 
    mContext = context; 
} 

public void onAnimationStart(Animation animation) { 
    changeView.post(new SwapViews(changeView, image)); 
    changeView.postDelayed(new SwapViews(changeView, null), 1000); 
} 

public void onAnimationEnd(Animation animation) { 
    if (mIsCorrect == false) { 
     mContext.finish(); 
    } 
} 

public void onAnimationRepeat(Animation animation) { 

} 
} 

そして、あなたのapplyRotationは推測が正しかったかどうかを渡す必要があります:

private void applyRotation(View parChangeView, Drawable image, float start, 
     float end, boolean isCorrect) { 
    // Find the center of image 
    final float centerX = parChangeView.getWidth()/2.0f; 
    final float centerY = parChangeView.getHeight()/2.0f; 

    // Create a new 3D rotation with the supplied parameter 
    // The animation listener is used to trigger the next animation 
    final Flip3DAnimation rotation = new Flip3DAnimation(start, end, 
      centerX, centerY); 
    rotation.setDuration(250); 
    rotation.setFillAfter(true); 
    rotation.setInterpolator(new AccelerateInterpolator()); 
    rotation.setAnimationListener(new DisplayNextView(parChangeView, image, isCorrect, this)); 
    parChangeView.startAnimation(rotation); 
    // return rotation; 
} 
関連する問題