1

アニメーションを使用して、 Ludo ボードで画像 (トークン) を下から上、左から右に変換したいだけです。このために、すべてのトークン(赤、青、黄、緑の色)が移動する場所からすべての ImageView の座標を取得しましたが、今は行き詰まっています。次に何をすればいいですか?私はAndroidアニメーションが初めてです。どうすればそれができますか?

これは私の配列インデックスコードです:

public void onCreate( Bundle savedInstanceState ) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.start );
    double aPowersOfTwo[] = new double[60];
    aPowersOfTwo[0]=Math.pow(81,263);
    aPowersOfTwo[1]=Math.pow(50,262);
    aPowersOfTwo[2]=Math.pow(50,231);
    aPowersOfTwo[3]=Math.pow(80,227);
}

黄色のトークンの私のJavaコードは

switch(rand.nextInt(6) + 1)

    {
    case 1:

        diceImage.setImageResource(R.drawable.dice_one);
        yellowToken.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                switch(v.getId()){
                case R.id.yellow_token9:
                    Animation animation = new TranslateAnimation(0,80,0,48);
                    animation.setDuration(1500);
                    animation.setFillAfter(true);
                    yellowToken.startAnimation(animation);
                    yellowToken.setVisibility(0);


                    break;
            }   
        }});

    case 2:
        diceImage.setImageResource(R.drawable.dice_two);
        Log.d("dice", "2");
        break;
    case 3:

        diceImage.setImageResource(R.drawable.dice_three);
        Log.d("dice", "3");
        break;

    case 4:

        diceImage.setImageResource(R.drawable.dice_four);
        Log.d("dice", "4");
        break;
    case 5:

        diceImage.setImageResource(R.drawable.dice_five);
        Log.d("dice", "5");
        break;
    case 6:

        diceImage.setImageResource(R.drawable.dice_six);
        yellowToken.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                switch(v.getId()){
                case R.id.yellow_token9:
                    Animation animation = new TranslateAnimation(0,80,0,48);
                    animation.setDuration(1500);
                    animation.setFillAfter(true);
                    yellowToken.startAnimation(animation);
                    yellowToken.setVisibility(0);
                    break;
            }
        }});  

私のxmlコードは

<ImageView
android:id="@+id/yellow_token9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginTop="222dp"
android:clickable="true"
android:background="@drawable/yellow"/> 
4

2 に答える 2

0
  1. 私はこのゲームを開発したので、サイコロを投げるとトークンが自動的に移動し、コインを移動する魔法がなくなると想定していますが、そうではなく、タッチ時に動きをアニメートしたい場合は問題ありません。

  2. 私が気付いたもう 1 つのことは、配列のサイズです。何かが欠けていない限り、64 である必要があります。ボードの画像については、私のブログをご覧ください。http://ravichandranjv.blogspot.in

imageView をトークンとして使用している場合、アニメーションの可能性もあるドラッグ アンド ドロップを使用できますか? もちろん、ご存じのとおり、質問に対する見方が限られているため、具体的な答えを念頭に置いていない限り、すぐに使えるコードを提供することは困難です。

于 2013-05-06T21:50:58.690 に答える