[英]Slick2d java game crashing when I setBackground();
I'm using slick2d and in my Java application. 我在Java应用程序中使用slick2d。 In my render method I use a method called changeBackground(); 在我的渲染方法中,我使用了一个名为changeBackground()的方法。
@Override
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
throws SlickException {
changeBackground(g);
}
changeBackground(); 换背景();
public void changeBackground(Graphics g) throws SlickException{
Thread.sleep(500);
g.setBackground(new org.newdawn.slick.Color(0, 255, 0);
Thread.Sleep(500);
g.setBackground(new org.newdawn.slick.Color(255, 0, 0);
changeBackground(g);
}
When I run my application the game crashes. 当我运行我的应用程序时,游戏崩溃。
You are probably getting a stack overflow. 您可能会出现堆栈溢出。
public void changeBackground(Graphics g) throws SlickException{
Thread.sleep(500);
g.setBackground(new org.newdawn.slick.Color(0, 255, 0);
Thread.Sleep(500);
g.setBackground(new org.newdawn.slick.Color(255, 0, 0);
changeBackground(g); // you're calling this funct again! BAD
}
Remove the last line and hopefully you won't crash in that spot. 删除最后一行,希望您不会在该位置崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.