为了账号安全,请及时绑定邮箱和手机立即绑定

为什么这不能创建缓冲策略?

为什么这不能创建缓冲策略?

jeck猫 2023-11-10 15:24:19
我收到一个Exception in thread "Thread-3" java.lang.InternalError: Could not create a buffer strategy错误,该错误可以追溯到 Java 的基本代码,它可以追溯到下面第 58 ( render();) 和 77 ( this.createBufferStrategy(5);) 行的 Game 类。任何帮助都会很棒,如果您需要查看其他类,我还将我的所有代码上传到 github (mitisme/mit)。import java.awt.Canvas;import java.awt.Color;import java.awt.*;import java.awt.image.BufferStrategy;public class Game extends Canvas implements Runnable {   private static final long serialVersionUID = 1L;   private boolean isRunning = false;   private Thread thread;   private Handler handler;   //Creates background window size and holds objects by handler   public Game() {      Screen myScreen = new Screen(1280, 720, "Deed", this);      start();      handler = new Handler();      addKeyListener(new KeyInput(handler));      handler.addObject(new Player(425, 745, ID.Player, handler));   }//starts a new thread   private void start() {      isRunning = true;      thread = new Thread(this);      thread.start();   }   // Stops current thread, and catches exceptions   private void stop() {      isRunning = false;      try {         thread.join();      } catch (InterruptedException e) {         e.printStackTrace();      }   }   //Infinite game loop   public void run() {      this.requestFocus();      long lastTime = System.nanoTime();      double amountOfTicks = 60.0;      double ns = 1000000000 / amountOfTicks;      double delta = 0;      long timer = System.currentTimeMillis();      int frames = 0;      while(isRunning) {         long now = System.nanoTime();         delta += (now - lastTime) / ns;         lastTime = now;         while(delta >= 1) {            tick();            delta--;         }         render();         frames++;         if(System.currentTimeMillis() - timer > 1000) {            timer += 1000;            frames = 0;         }      }      stop();   }
查看完整描述

1 回答

?
LEATH

TA贡献1936条经验 获得超6个赞

我发现,这条线this.createBufferStrategy(5);只能从2-4创建缓冲策略,否则会出错。



查看完整回答
反对 回复 2023-11-10
  • 1 回答
  • 0 关注
  • 49 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信