ludo游戏中的android图像动画

时间:2013-04-11 22:28:04

标签: android animation imageview

我有一个ludo板的布局,其中我想根据骰子的数字移动我的标记。如果骰子掷骰数是6,我们将点击的图像视图应该移动6,如果它是4那么根据Ludo 4个地方板。 我的问题是我们如何修复所有董事会职位,以便我们的代币将根据骰子数量移动。 这是我的活动

public void onCreate( Bundle savedInstanceState )
{
    super.onCreate( savedInstanceState );
    setContentView( R.layout.first_page );

    ImageView iv = new ImageView(this);
   iv.setImageResource(R.drawable.token);




    rollerButton = (Button)findViewById( R.id.rolldice );
    image = (ImageView) findViewById(R.id.dice);
    board = (ImageView) findViewById(R.id.board);

    rollerButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch(v.getId())
            {
            case R.id.rolldice:
                Log.d("clicked", "button");
                startAnimation(image);

            }

        }
    });

    board.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //Choose which motion action has been performed


            switch(event.getAction())
            {
            case MotionEvent.ACTION_DOWN:
                //Get X, Y coordinates from the ImageView
                X = (int) event.getX();
                Y = (int) event.getY();

                position1=new ArrayList<Integer>();


                position1.add(X);
                position1.add(Y);



                for(int i=0;i<position1.size();i++)
                {
                    position1.get(i);
                }

                Log.d("X COordinate",""+X);
                Log.d("Y COordinate",""+Y);

                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
            }
            return true;
        }
});





}


public void startAnimation(View view) {

    switch (view.getId()) {


    case R.id.dice:

        Animation animation = new TranslateAnimation(0, 100,0, -100);
        animation.setDuration(1500);
        animation.setFillBefore(true);
        image.startAnimation(animation);
        image.setVisibility(0);
        break;      

    default:
        break;
    }

}

@Override
public void onAnimationEnd(Animation animation) {
    // TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
    // TODO Auto-generated method stub

}

@Override
public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub

}
}

1 个答案:

答案 0 :(得分:1)

您可以为所有位置创建坐标x,y的二维数组类,并在imageview中使用动画。然后根据该类的索引进行调用。