0
int label_x = (WIDTH / 2);
int label_y = (HEIGHT / 2);
GLabel label = newGLabel("0");
add(window, label);
setLocation(label, label_x, label_y );
return label;

In this way of initilizing scoreboard ,it seems like it is not centered in the window. Any ideas? (I changed default window height to 500 by the way)

1 Answer 1

3

My guess is that the score is being displayed slightly low and slightly right of center. This is because setLocation() will place the object based on the upper left corner of the object, not the center of the object. You have to account for the width and height of the label, the same as you had to for the ball, the paddle and the bricks.

I'll leave it to you to figure out how to code it. Can't take all the fun away from you. ;-)

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .