我在场景中有 10 张图片作为精灵。它们在一个数组中。图片(精灵)通过 MoveModifier 在场景中移动。我想要这个:当我触摸任何图片时,我触摸的图片应该是不可见的。我的代码不起作用,因为 19. line(circles[i].setVisible(false);) eclipse 说我将 i(variable) 作为 final。我不能这样做,因为我应该更改它的数组索引。什么我可不可以做?
final int totalCircleNumber=10;
int circleNumber=0;
private Sprite[] circles = new Sprite[totalCircleNumber];
private Runnable mStartCircle = new Runnable() {
public void run() {
int i=circleNumber++;
Scene scene = Level1Activity.this.mEngine.getScene();
float startX = randomNumber.nextFloat()*(CAMERA_WIDTH);
float startY = -64.0f;
float finishX= randomNumber.nextFloat()*(CAMERA_WIDTH);
float finishY= CAMERA_HEIGHT+64.0f;
int j= randomNumber.nextInt(50);
circles[i] = new Sprite(startX, startY, textRegCircle[j]){
@Override
public boolean onAreaTouched(final TouchEvent pAreaTouchEvent,final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
if(pAreaTouchEvent.isActionDown())
{
circles[i].setVisible(false);
}
return true;
}
};
scene.registerTouchArea(circles[i]);
circles[i].registerEntityModifier(
(IEntityModifier) new SequenceEntityModifier (
new MoveModifier(velocityOfCircle, circles[i].getX(), finishX,
circles[i].getY(), finishY)));
scene.getLastChild().attachChild(circles[i]);
if (circleNumber < totalCircleNumber){
mHandler.postDelayed(mStartCircle,second);
}
}
};