2012-01-01 59 views
2

画面全体で画像を移動する方法は?Androidで画面全体に画像を移動する方法

みんな、私のコースワーク用のMoleMashゲームを作成しています。本当に助けが必要です。私は、異なるランダムな座標で画面全体に画像(モル)を移動して、スコアを得るためにユーザーに触れることができるようにしたいと考えています。私はイメージビューを作成した背景を作成しました。私はモルを持っています、それは別のイメージビューですか?またはImageボタンですか?

ユーザーインタラクションのために、これを画面の別の部分に移動するにはどうすればよいですか?

私はあなたの助けに感謝します!

答えて

2

How can I use the animation framework inside the canvas?

onTouchイベントリスナーを使用して、あなたのアニメーション画像の位置がタッチ位置を比較するでしょう...

+0

(私はのTextViewをアニメーション私の場合..あなたは、ImageViewのを渡します) Androidのアニメーションフレームワークについて知る必要があります:http://developer.android.com/training/animation/index.html - 別の代替方法はOpenGLですが、その場合はOpenGLSurfaceビューについて知る必要があります。 – AgentKnopf

0

モルはイメージボタンになるのでクリックすることができますが、移動させるにはアニメーションを使用する必要があります。私はAndroidアニメーションの初心者でもあることに留意してください:)。あなたはおそらくTranslateAnimationを使用して、パラメータのxとyをランダム変数に設定します。時間は、ゲームが開始した後のある時点に時間/カウンタ変数が達したときです。この投稿にはアニメーションに関する詳細情報があります:How to move an image from left to right in androidあなたがキャンバスとSurfaceViewを使用する方法を学習する必要があるゲーム開発のための

0

このコードを試してみてください、

宣言次の変数のonCreate()で

private Random random=new Random(); 

private int screenwidth, screenhgt; 

screenwidth= getyourScreenWidth; 

screenhgt=getyourscreenheight; 

は、このメソッドにビューを渡すあなたはしかし、行うような場合、単純なanimation.Inをやっている場合は、SurfaceViewを必要といけない

private void screenRandomAnimator(final TextView textView) { 

    final AnimatorSet mAnimatorSet = new AnimatorSet(); 
    mAnimatorSet.playTogether(ObjectAnimator.ofFloat(textView, "x", (float) random.nextInt(screenwidth), (float) random.nextInt(screenwidth)), 
      ObjectAnimator.ofFloat(textView, "y", (float) random.nextInt(screenhgt), (float) random.nextInt(screenhgt)), ObjectAnimator.ofFloat(textView, "rotation", 360) 
     /* ObjectAnimator.ofFloat(textView, "scaleX", 1, 0.8f, 1, 1.1f, 1), ObjectAnimator.ofFloat(textView, "scaleY", 1, 0.8f, 1, 1.1f, 1)*/); 
    int Low = 1500; 
    int High = 2500; 
    int Result = random.nextInt(High - Low) + Low; 
    mAnimatorSet.setDuration(Result); 
    mAnimatorSet.start(); 
    mAnimatorSet.addListener(new Animator.AnimatorListener() { 
     @Override 
     public void onAnimationStart(Animator animation) { 

     } 

     @Override 
     public void onAnimationEnd(Animator animation) { 
      mAnimatorSet.playTogether(ObjectAnimator.ofFloat(textView, "x", textView.getX(), (float) random.nextInt(screenwidth)), 
        ObjectAnimator.ofFloat(textView, "y", textView.getY(), (float) random.nextInt(screenhgt))); 
      int Low = 1500; 
      int High = 2500; 
      int Result = random.nextInt(High - Low) + Low; 
      mAnimatorSet.setDuration(Result); 
      mAnimatorSet.start(); 
     } 

     @Override 
     public void onAnimationCancel(Animator animation) { 

     } 

     @Override 
     public void onAnimationRepeat(Animator animation) { 

     } 
    }); 
} 
関連する問題