【发布时间】:2011-03-29 01:09:01
【问题描述】:
我正在尝试为我正在开发的游戏初始化一个 3D 数组,经过多次语法更改后,我无法弄清楚如何让它工作!我一开始是:
public class AnimationView extends SurfaceView implements SurfaceHolder.Callback {//Create bitmaps.
Bitmap bitmapGoal = BitmapFactory.decodeResource(this.getResources(), R.drawable.goal);
Bitmap bitmapOrig = BitmapFactory.decodeResource(this.getResources(), R.drawable.ball);
Bitmap bitmap = Bitmap.createScaledBitmap(bitmapOrig, 150, 150, true);
//initialize the canvas.
private Canvas c;
private int score[] = {0, 0, 0, 0};
public int numBalls = 1;
//we support up to 4 balls. thus each array is 4 bit.
private int ballX[] = {0, 200, 400, 600};
private double ballY[] = {0, 0, 0, 0};
private double dirV[] = {0, 0, 0, 0};
private int dirH[] = {30, 30, 30, 30};
private static final int SCALE = 10;
private double elasticity = .6;
private int rotationNow[] = {5, 5, 5, 5};
private int rotationDraw[] = {0, 0, 0, 0};
class AnimationThread extends Thread {
//Are we running currently?
private boolean mRun;
//layer 1 is how many balls, 4 layers deep.
//layer 2 is which ball we're talking about, either 1, 2, 3, or 4 layers deep, depending on layer 1.
//layer 3 is the bounds of the ball, dependent on how many there are total.
//layer 3 is formatted x-min, x-max, y-min, y-max
int[][][] bounds = new int[][][] {
{ {0, c.getWidth() - bitmap.getWidth(), 0, c.getHeight() - bitmap.getHeight()}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0} },
//end first layer
{ {0, c.getWidth() / 2 - bitmap.getWidth(), 0, c.getHeight() - bitmap.getHeight()}, {c.getWidth() / 2, c.getWidth() - bitmap.getWidth(), 0, c.getHeight() - bitmap.getHeight()}, {0, 0, 0, 0}, {0, 0, 0, 0} },
//end second layer
{ {0, c.getWidth() / 3 - bitmap.getWidth(), 0, c.getHeight() - bitmap.getHeight()}, {c.getWidth() / 3, c.getWidth() * 2 / 3 - bitmap.getWidth(), 0, c.getHeight() - bitmap.getHeight()}, {c.getWidth() * 2 / 3, c.getWidth() - bitmap.getWidth(), 0, c.getHeight() - bitmap.getHeight()}, {0, 0, 0, 0} },
//end third layer
{ {0, c.getWidth() / 2, 0, c.getHeight() / 2}, {c.getWidth() / 2, c.getWidth(), 0, c.getHeight() / 2}, {0, c.getWidth() / 2, c.getHeight() / 2, c.getHeight()}, {c.getWidth() / 2, c.getWidth(), c.getHeight() / 2, c.getHeight()} }
//end fourth, and final layer!
};
对于奇怪的格式错误,我们深表歉意。我知道这没有任何帮助。在 ymax 和 int[][][] 之间有一个新行。 您并不完全需要仔细阅读并理解它,但它会编译然后在执行过程中出错。于是我尝试制作一个简单的 3D 数组,我从以下内容开始:
int[][][] bounds = new int[1][1][1];
bounds[0][0][0] = 0;
Eclipse 在第一行的分号下有红色波浪状的。说 '令牌“;”上的语法错误,{ 应在此令牌之后'
这就是令人沮丧的地方。因为将完全相同的代码复制/粘贴到常规 Java 程序中工作正常,但我无法让它在 Android 项目中工作。然后我将一些东西简化为:
int[] bounds = new int[1];
bounds[0] = 0;
完全相同的错误,完全相同的位置!为什么是日食??我也尝试使用“int bounds[][][]”而不是“int[][][] bounds”,但没有区别,仍然是同样的错误。
我已经重新启动了我的计算机,多次清理了我的项目,重新启动了 Eclipse。我没主意了。你有什么??
【问题讨论】:
-
我们能看到更多代码吗? (可能是
int[][][] bounds...之前的内容) -
一般来说,一个未闭合的括号或缺少分号before这个语句会导致这样的错误,因为解析器认为这一行也是前一行的一部分。
-
@euphoria83 看到我的回答。通常是在这句话之后。
标签: java android arrays eclipse