Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Ludo板中使用数组索引_Java_Android_Animation_Imageview_Coordinates - Fatal编程技术网

Java 如何在Ludo板中使用数组索引

Java 如何在Ludo板中使用数组索引,java,android,animation,imageview,coordinates,Java,Android,Animation,Imageview,Coordinates,我只想在Ludo board中使用动画从下到上、从左到右翻译图像(标记)。为此,我获取了每个图像视图的坐标,其中每个标记(红色、蓝色、黄色、绿色)都将移动,但现在我被卡住了;接下来我该怎么办?我是Android动画新手。我怎么能这么做 这是我的数组索引代码: public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView( R.layo

我只想在Ludo board中使用动画从下到上、从左到右翻译图像(标记)。为此,我获取了每个图像视图的坐标,其中每个标记(红色、蓝色、黄色、绿色)都将移动,但现在我被卡住了;接下来我该怎么办?我是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"/> 

  • 因为我已经开发了这个游戏,我假设掷骰子时,代币会自动移动,这会带走移动硬币的魔力,但如果没有,并且你想在触摸时设置移动动画,那么就可以了

  • 我注意到的另一件事是数组的大小——应该是64,除非我遗漏了什么。你可以在我的博客上查看董事会的图片


  • 如果您使用imageView作为标记,是否可以使用同样具有动画可能性的拖放?当然,正如您所知,鉴于您对问题的看法有限,除非您有具体的答案,否则很难提供现成的代码。

    因为您将所有坐标存储在数组中,但使用了错误的方法Math.pow(x,y)它是用来表示x到y的幂的。所以你应该使用二维数组来存储所有坐标。这样做之后,你可以使用这个概念来开发这个游戏-

    范例-

    如果骰子显示“1”,你应该将你的索引增加“1”,并在你的骰子中进行坐标传递

    TranslateAnimation()方法


    然后根据索引编号将它们移动到正确的位置。

    根据骰子编号,我想增加数组索引,这样在单击“图像视图”时,我就可以使用平移动画,而且我不知道如何在translateAnimation()中使用此数组。因为我们给出了x,初始位置标记的y坐标,如示例yellowToken.setOnClickListener(新OnClickListener(){@Override public void onClick(视图v){//TODO自动生成的方法存根开关(v.getId()){case R.id.yellow\u标记9:动画=新的TranslateAnimation(0,80,0,48);animation.setDuration(1500);animation.setFillAfter(true);yellowToken.startAnimation(animation);yellowToken.setClickable(false);yellowToken.startAnimation(animation);break;那么我们如何在translateAnimation()中给出索引坐标呢。抱歉这么晚才回复,我不在这个论坛。我希望它有一个电子邮件通知设置。您的切换条件v.getId()没有得到评估或使用,R.id.yellow_令牌案例与该条件无关。您没有评估v.getId()