I've tried this solution:
gc.fillOval( go.topX, go.topY, go.width, go.height );
But it changes all the gameobjects to oval. I want only the ball to change!
Part of the code:
public void drawPicture()
{
// the game loop is running 'in the background' so we have
// add the following line to make sure it doesn't change
// the model in the middle of us updating the image
synchronized ( model )
{
// get the 'paint brush' to pdraw on the canvas
GraphicsContext gc = canvas.getGraphicsContext2D();
// clear the whole canvas to white
gc.setFill( Color.WHITE );
gc.fillRect( 0, 0, width, height );
// draw the bat and ball
displayGameObj( gc, ball ); // Display the Ball
displayGameObj( gc, bat ); // Display the Bat
// *[2]****************************************************[2]*
// * Display the bricks that make up the game *
// * Fill in code to display bricks from the brick array *
// * Remember only a visible brick is to be displayed *
// ************************************************************
for (GameObj brick: bricks) {
if (brick.visible) {
displayGameObj(gc, brick);
}
}
// update the score
infoText.setText("BreakOut: Score = " + score);
}
}
// Display a game object - it is just a rectangle on the canvas
public void displayGameObj( GraphicsContext gc, GameObj go )
{
gc.setFill( go.colour );
gc.fillRect( go.topX, go.topY, go.width, go.height );
}