# BufferStrategy Flackert



## RegenSonne (7. Sep 2017)

Hi mal wieder,
ich habe ein Problem. ich habe ein platform spiel geschrieben aber es flackert wenn man die maus bewegt...

Kann mir wer erklären woran das liegt?


```
protected void render() {
  
  BufferStrategy bs = this.getBufferStrategy();
  if (bs == null) {
   this.createBufferStrategy(3);
   return;
  }
  Graphics g = bs.getDrawGraphics();
  Graphics2D g2d = (Graphics2D) g;
  g.setColor(Color.black);
  g.fillRect(0, 0, Gui.WIDTH, Gui.HEIGHT);
  g.drawImage(bg, 0, 0, null);
  
  if (Gui.inGame) {
   
   g2d.translate(cam.getX(), cam.getY()); // Begin of cam
   handler.render(g);
   g2d.translate(-cam.getX(), -cam.getY()); // end of cam
  }
  if (Gui.inGame != true) {
   Particle.renderParticles(g);
   ParticleBackground.renderParticles(g);
  }
  Gui.renderAllButtons(g);
  if (Gui.inMenu) {
   if (Draw.guiSelected == 0) {
    g.setColor(new Color(0.8f, 0f, 0f, 0.4f));
   } else if (Draw.guiSelected == 1) {
    g.setColor(new Color(0.0f, 0f, 0.8f, 0.4f));
   } else if (Draw.guiSelected == 2) {
    g.setColor(new Color(1f, 1f, 0.3f, 0.4f));
   }
   g.drawString(coder, 10, 680);
   int stringWidth = g.getFontMetrics().stringWidth("CircleAttack");
   if (Draw.guiSelected == 0) {
    g.setColor(new Color(0.8f, 0f, 0f, 0.4f));
   } else if (Draw.guiSelected == 1) {
    g.setColor(new Color(0.0f, 0f, 0.8f, 0.4f));
   } else if (Draw.guiSelected == 2) {
    g.setColor(new Color(1f, 1f, 0.3f, 0.4f));
   }
   g.fillRect(Gui.WIDTH / 2 - stringWidth, -3, 120, 50);
   g.setColor(Color.black);
   g.drawRect(Gui.WIDTH / 2 - stringWidth, -3, 120, 50);
   if (Draw.guiSelected == 0) {
    g.setColor(new Color(0.8f, 0f, 0f));
   } else if (Draw.guiSelected == 1) {
    g.setColor(new Color(0.0f, 0f, 0.8f));
   } else if (Draw.guiSelected == 2) {
    g.setColor(new Color(1f, 1f, 0.3f));
   }
   g.drawString("CircleAttack", Gui.WIDTH / 2 - stringWidth + 25, 27);
   g.drawString(version, 1235, 20);
   int hour = LocalDateTime.now().getHour();
   int min = LocalDateTime.now().getMinute();
   g.setFont(new Font("Verdana", Font.BOLD, 40));
   if (mouseX >= 1190 && mouseX <= 1300 && mouseY >= 540 && mouseY <= 670) {
    if (Draw.guiSelected == 0) {
     g.setColor(new Color(0.8f, 0f, 0f, 0.4f));
    } else if (Draw.guiSelected == 1) {
     g.setColor(new Color(0.0f, 0f, 0.8f, 0.4f));
    } else if (Draw.guiSelected == 2) {
     g.setColor(new Color(1f, 1f, 0.3f, 0.4f));
    }
   } else {
    g.setColor(new Color(0f, 0f, 0f, 0.4f));
   }
   g.drawLine(1200, 550, 1260, 550);
   g.drawLine(1200, 670, 1260, 670);
   g.drawString("" + hour, 1200, 600);
   g.drawString("" + min, 1200, 650);
  } else if (Gui.inOptions) {
  } else if (Gui.inPause) {
  } else if (Gui.inShop) {
  } else if (Gui.inGuiSelecter) {
   g.setColor(Color.YELLOW);
   int guiSelectedf = guiSelected + 1;
   g.drawString("Gui: " + guiSelectedf, 1220, 670);
  }
  g.dispose();
  bs.show();
 }
```

LG und vielen Dank ^^


----------



## Robat (7. Sep 2017)

Das Flackern kann verschiedene Gründe haben.
Häufig ist ein Grund dass die FPS Anzahl nicht limitiert ist.
Wie sieht das bei dir aus? Hast du in deiner Schleife ein Delay drin?


----------



## RegenSonne (8. Sep 2017)

nein habe ich nicht.. es sind 60 ticks aber mehrere Millionen Frames glaube ich..


----------



## RegenSonne (8. Sep 2017)

Auch mit 60 fps flackert es...


----------

