I am working on game development in android
I have a class called droid in my model package and i have a constructor called update() in my main game panel class
I would like to make an array of droids and access them in my main game panel and from constructors within the main game panel class. I am able to do this from the main game panel constructor but not from the update constructor. ie Whenever I try to access the x position of one of the droids in the update constructor of the main game panel class I get this error: "The type of the expression must be an array type but it resolved to Droid"
package net.test.droid.model;
public class Droid {
private Bitmap bitmap; // the actual bitmap
private int x; // the X coordinate
private int y;
private boolean touched; // if droid is touched/picked up
public Droid(Bitmap bitmap, int x, int y) {
this.bitmap = bitmap;
this.x = x;
this.y = y;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public void draw(Canvas canvas) {
canvas.drawBitmap(bitmap, x, y, null);
}
}
in main game
public class MainGamePanel extends SurfaceView implements
SurfaceHolder.Callback {
public Droid droid_array;
public MainGamePanel(Context context) {
super(context);
// adding the callback (this) to the surface holder to intercept events
getHolder().addCallback(this);
Droid[] droid_array = new Droid[5];
for (int i = 0; i < 5; i++) {
droid_array[i] = new Droid(BitmapFactory.decodeResource(
getResources(), R.drawable.ic_launcher), droid_x_pos + i*10, droid_y_pos);
}
droid_array[1].setX(666);
}
the last line works fine however whenI try to use it in update() I get the error
public void update() {
test=droid_array[1].getX();
}
the above line returns error "The type of the expression must be an array type but it resolved to Droid"