0

I have a bug in my breakout code. For some reason the ball is arranged behind the score. I even put the code to fix it twice (used both sendBackward and sendToFront). But it didn't help. I need an advice on how to fix this. Thank you.

    GOval initBall(GWindow window)
{
    GOval ball = newGOval(WIDTH / 2 - 25 / 2, HEIGHT / 2 - 25 / 2, 25, 25);
    setColor(ball, "BLACK");
    setFilled(ball, true);
    add(window, ball);
    sendToFront(ball);
    return ball;
}

/**
 * Instantiates paddle in bottom-middle of window.
 */
GRect initPaddle(GWindow window)
{
    GRect paddle = newGRect(WIDTH / 2 - PADDLE_WIDTH / 2, HEIGHT - 50, PADDLE_WIDTH, PADDLE_HEIGHT);
    setColor(paddle, "BLACK");
    setFilled(paddle, true);
    add(window, paddle);  
    return  paddle;
}

/**
 * Instantiates, configures, and returns label for scoreboard.
 */
GLabel initScoreboard(GWindow window)
{
    GLabel label = newGLabel("0");
    setFont(label, "ComicSans-bold-40");
    setColor(label, "#eee7ec");

    double x = (getWidth(window) - getWidth(label)) / 2;
    double y = (getHeight(window) - getHeight(label)) / 2;
    setLocation(label, x, y);
    sendBackward(label);
    add(window, label);
    return label;
}

You must log in to answer this question.

Browse other questions tagged .