I got an instance variable of type GRect
private GRect brick;
that I create several of, through iteration
private void makeBrickLineX(int x, int y, Color color)
{
for (int i = 0; i < NBRICKS_PER_ROW; i++,
x += BRICK_WIDTH + BRICK_SEP) // Sets the x locations and separation between each brick.
{
GRect brick = new GRect (BRICK_WIDTH, BRICK_HEIGHT);
brick.setFilled(true);
brick.setColor(color);
add(brick, x,y);
}
}
The problem is, I am creating a "breakout" game, and I need to know when the ball has hit a brick. The code for it is simple, I use a method called getElementAt (balls x & y location) this all works. But there are several bricks, and calling remove on brick remove (brick)
. Only removes one brick in lowermost right corner, so these bricks must not share the same name? What can I do to make it work with all instances of "brick".