I have made a game with 20+ classes in it and if I run the application in Eclipse it perfectly works.
Now if I export the game to a runnable jar, it gets stuck when I try to launch the game. But the weird thing is that my intro plays and I can continue by pressing "enter" to my menu, but if I try to start the game from there, the menu gets stuck. (normally the background of my menu moves)
So, I have three GameState
wich are called introState
, menuState
and level1State
. These three all extend from GameState. introState and menuState work perfectly but level1State doesn't.
I'll put the code from level1State and the manifestfile here. Eclipse doesn't give me any errors.
My game does have a Main-class and every class displayed does exist and works.
Any ideas on what causes this and how to solve this? Or maybe another way to play this game outside eclipse?
package GameState;
import Main.GamePanel;
import TileMap.*;
import Entity.*;
import Entity.Enemies.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
package GameState;
import Main.GamePanel;
import TileMap.*;
import Entity.*;
import Entity.Enemies.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
public class Level1State extends GameState {
private TileMap tileMap;
private Background bg;
private Player player;
private ArrayList<Enemy> enemies;
private HUD hud;
public Level1State(GameStateManager gsm) {
this.gsm = gsm;
init();
}
public void init() {
tileMap = new TileMap(30);
tileMap.loadTiles("/Tilesets/darktheme.gif");
tileMap.loadMap("/Maps/level1-1.map");
tileMap.setPosition(0, 0);
tileMap.setTween(1);
bg = new Background("/Backgrounds/backgroundbg.gif", 0.1);
player = new Player(tileMap);
player.setPosition(100, 100);
populateEnemies();
hud = new HUD(player);
}
private void populateEnemies() {
enemies = new ArrayList<Enemy>();
Slugger s;
Point[] points = new Point[] {
new Point(860, 200),
new Point(1525, 200),
new Point(1680, 200),
new Point(1800, 200)
};
for(int i = 0; i < points.length; i++) {
s = new Slugger(tileMap);
s.setPosition(points[i].x, points[i].y);
enemies.add(s);
}
Spin s1;
Point[] point = new Point[]{
new Point(1990,100)
};
for(int k = 0; k < point.length; k ++){
s1 = new Spin(tileMap);
s1.setPosition(point[k].x, point[k].y);
enemies.add(s1);
//System.out.println(point[k].y);
}
}
public void update() {
// update player
player.update();
tileMap.setPosition(
GamePanel.WIDTH / 2 - player.getx(),
GamePanel.HEIGHT / 2 - player.gety()
);
// set background
bg.setPosition(tileMap.getx(), tileMap.gety());
// attack enemies
player.checkAttack(enemies);
// update all enemies
for(int i = 0; i < enemies.size(); i++) {
Enemy e = enemies.get(i);
e.update();
if(e.isDead()) {
enemies.remove(i);
i--;
}
}
}
public void draw(Graphics2D g) {
// draw bg
bg.draw(g);
// draw tilemap
tileMap.draw(g);
// draw player
player.draw(g);
// draw enemies
for(int i = 0; i < enemies.size(); i++) {
enemies.get(i).draw(g);
}
// draw hud
hud.draw(g);
}
public void keyPressed(int k) {
if(k == KeyEvent.VK_LEFT) player.setLeft(true);
if(k == KeyEvent.VK_RIGHT) player.setRight(true);
if(k == KeyEvent.VK_UP) player.setUp(true);
if(k == KeyEvent.VK_DOWN) player.setDown(true);
if(k == KeyEvent.VK_SPACE) player.setJumping(true);
if(k == KeyEvent.VK_E) player.setGliding(true);
if(k == KeyEvent.VK_A) player.setScratching();
if(k == KeyEvent.VK_F) player.setFiring();
}
public void keyReleased(int k) {
if(k == KeyEvent.VK_LEFT) player.setLeft(false);
if(k == KeyEvent.VK_RIGHT) player.setRight(false);
if(k == KeyEvent.VK_UP) player.setUp(false);
if(k == KeyEvent.VK_DOWN) player.setDown(false);
if(k == KeyEvent.VK_SPACE) player.setJumping(false);
if(k == KeyEvent.VK_E) player.setGliding(false);
}
}
Manifest file:
Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Rsrc-Main-Class: Main.Game
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
DId you export it as a runnable JAR or as a JAR file? Try both if you haven't yet. I use the same engine and it works for me but i exported it as a jar it didn't work completely while when I exported it as a runnable JAR file it does work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.