Joshi Minh
Joshi Minh

Reputation: 1

How to solve this graphic problem in my Java Flappy Bird game?

So here is a picture of my Flappy Bird gameplay:

https://i.sstatic.net/V8ReB.png

And here is the code for the graphics, display part using Java Swing JPanel:

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // Draw background image
    backgroundImage.paintIcon(this, g, 0, 0);

    // Draw obstacles
    for (Rectangle obstacle : obstacles) {
        int pipeSpace = space; // space between upper and lower pipes
        int lowerPipeHeight = 600 - obstacle.height - pipeSpace;

        // Draw lower pipe
        g.drawImage(lowerPipeIcon.getImage(), obstacle.x, obstacle.y
                + obstacle.height + pipeSpace, obstacle.width,
                lowerPipeHeight, this);

        // Draw upper pipe
        g.drawImage(upperPipeIcon.getImage(), obstacle.x, obstacle.y,
                obstacle.width, obstacle.height, this);
    }
}

As you can see, the below pipes are always looks not normal, I tried many ways to fix the code, but it just gone worse.

Here is the link to the game files on Github.

Most of the game code is in the Launcher and FlappyBird java files for anyone who wants to read the full code and I would love to wait for a god from the sky to descend and help me solve this chronic problem.

Upvotes: 0

Views: 230

Answers (0)

Related Questions