我是 android 游戏开发的新手,我正在使用 AndEngine GLES 2 Java。我收到一个错误,这与我的数组(face1)具有非法索引有关。我无法解决问题,所以我需要一些帮助。代码:
@Override
public Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
final float centerX1 = 400;
final float centerY1 = 50;
final Sprite[] face1 = new Sprite[i];
face1[i] = new Sprite(centerX1, centerY1, this.m2FaceTextureRegion, this.getVertexBufferObjectManager());
final float centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
final float centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager()) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
if(!face1[i].collidesWith(this))
{
x+=1;
this.setPosition(x, 50 );
}
else
{
x=60;
this.setPosition(x, 50 );
}
return true;
}
};
scene.attachChild(face);
scene.registerTouchArea(face);
scene.setTouchAreaBindingOnActionDownEnabled(true);
face.setScale(4);
scene.attachChild(face1[i]);
face1[i].setScale(2);
return scene;
}
错误:
11-11 12:12:42.690: E/AndEngine(13291): java.lang.ArrayIndexOutOfBoundsException
谢谢。