#1 Members - Reputation: 345
Posted 23 August 2012 - 07:14 AM
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
Image mainMenuScreen = new Image("res/MainMenu.png");
Image playButton = new Image("res/playButton.png");
Image exitButton = new Image("res/ExitButton.png");
g.drawImage(mainMenuScreen, 0,0);
g.drawImage(playButton, 500, 220);
g.drawImage(exitButton, 500, 300);
}
now i have this code in another class:
Image play = new Image("res/Play.png");
Image Paddle1 = new Image("res/Paddle.png");
Image Paddle2 = new Image("res/Paddle.png");
g.drawImage(play,0,0);
g.drawImage(Paddle1,0,200);
g.drawImage(Paddle2,620,200);
this is my Game.java class:
package MyGame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame{
public static final String gamename = "Pong v.1";
public static final int mainmenu = 0;
public static final int play = 1;
public static final int menu = 2;
public static final int verdict = 3;
public Game(String gamename){
super(gamename);
this.addState(new MainMenu(mainmenu));
this.addState(new Play(play));
this.addState(new Menu(menu));
this.addState(new Verdict(verdict));
}
public void initStatesList(GameContainer gc) throws SlickException{
this.getState(mainmenu).init(gc, this);
this.getState(play).init(gc, this);
this.getState(menu).init(gc, this);
this.getState(verdict).init(gc, this);
this.enterState(mainmenu);
}
public static void main(String[] args) {
AppGameContainer appgc;
try{
appgc = new AppGameContainer(new Game(gamename));
appgc.setDisplayMode(680, 400, false); //Width length fullscreen
appgc.start();
}catch(SlickException e){
e.printStackTrace();
}
}
}
The screen shows up but in about 5 sec it closes.
"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"
"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"
#2 Moderators - Reputation: 5034
Posted 23 August 2012 - 07:23 AM
Is that literally the error message? Can you post the full error message, and any associated stack trace?I have these errors: Game.render() failure - check the game code
Does it appear to work for those 5 seconds? You are creating new images every frame. If these images allocate system resources (which it appears to have, you have a resource leak that will eventually cause your program to fail. Try moving the images into fields, and only loading them once at startup. If possible, ensure you are loading each image exactly once.The screen shows up but in about 5 sec it closes.
#3 Members - Reputation: 345
Posted 23 August 2012 - 07:34 AM
Edited by Mathew Bergen, 23 August 2012 - 07:38 AM.
"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"
"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"
#4 Crossbones+ - Reputation: 1062
Posted 23 August 2012 - 08:17 AM
BTW: put your code in so it gets formatted, otherwise it is a pain to read.
Setting fire to these damn cows one entry at a time!
#5 Members - Reputation: 345
Posted 23 August 2012 - 09:08 AM
[source lang="java"]hu Aug 23 08:03:47 PDT 2012 INFO:Slick Build #274Thu Aug 23 08:03:47 PDT 2012 INFO:LWJGL Version: 2.8.4Thu Aug 23 08:03:47 PDT 2012 INFO:OriginalDisplayMode: 1280 x 1024 x 24 @50HzThu Aug 23 08:03:47 PDT 2012 INFO:TargetDisplayMode: 680 x 400 x 0 @0HzThu Aug 23 08:03:48 PDT 2012 INFO:Starting display 680x400Thu Aug 23 08:03:48 PDT 2012 INFO:Use Java PNG Loader = trueThu Aug 23 08:03:48 PDT 2012 INFO:Controllers not availableThu Aug 23 08:03:50 PDT 2012 ERROR:Resource not found: res/MainMenu.pngjava.lang.RuntimeException: Resource not found: res/MainMenu.png at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:169) at org.newdawn.slick.Image.<init>(Image.java:196) at org.newdawn.slick.Image.<init>(Image.java:170) at org.newdawn.slick.Image.<init>(Image.java:158) at org.newdawn.slick.Image.<init>(Image.java:136) at MyGame.MainMenu.render(MainMenu.java:18) at org.newdawn.slick.state.StateBasedGame.render(StateBasedGame.java:199) at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:681) at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408) at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318) at MyGame.Game.main(Game.java:36)Thu Aug 23 08:03:50 PDT 2012 ERROR:Game.render() failure - check the game code.org.newdawn.slick.SlickException: Game.render() failure - check the game code. at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:684) at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408) at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318) at MyGame.Game.main(Game.java:36)[/source]
and in the debug window it shows this:
[source lang="java"]<terminated>Game (1) [Java Application] <terminated>MyGame.Game at localhost:48985 <terminated, exit value: 0>/usr/lib/jvm/java-6-openjdk-i386/bin/java (2012-08-23 8:03:47 AM) [/source]
However i removed the big image and it worked. Im not sure how to set it as the background so i set it to 0,0. the image takes up the whole space. How would i set it as the background?
also im not sure how to do the grey bar sorry.
Edited by Mathew Bergen, 23 August 2012 - 09:09 AM.
"C spilled his beer all over C++'s shirt. Outraged, C++ shouted, "Good god, man! Have you no class?"
"Your mother is so fat that the recursive function that was used to calculate her mass created a stack overflow"
#7 Members - Reputation: 167
Posted 23 August 2012 - 11:01 AM
Furthermode, it appears it can't find MainMenu.png, and throws an Exception, which leads to the top-level SlickException; that's your issue.






