java - Libgdx game Runs perfect in Eclipse, doesn't even open when Exported -
i creating game in java, using libgdx. worked fine when compiled until added layers tiled map. still runs fine when ran eclipse when compile runnable jar, not open. commented out layers , ran perfect again, have no idea causing issue.
here stack:
exception in thread "lwjgl application" java.lang.nullpointerexception @ com.mygdx.game.game_screen.render(game_screen.java:181) @ com.badlogic.gdx.game.render(game.java:46) @ com.badlogic.gdx.backends.lwjgl.lwjglapplication.mainloop(lwjglapplication.java:215) @ com.badlogic.gdx.backends.lwjgl.lwjglapplication$1.run(lwjglapplication.java:120)
and here code:
package com.mygdx.game; import com.badlogic.gdx.gdx; import com.badlogic.gdx.input; import com.badlogic.gdx.screen; import com.badlogic.gdx.graphics.gl20; import com.badlogic.gdx.graphics.orthographiccamera; import com.badlogic.gdx.graphics.texture; import com.badlogic.gdx.graphics.g2d.animation; import com.badlogic.gdx.graphics.g2d.spritebatch; import com.badlogic.gdx.graphics.g2d.textureregion; import com.badlogic.gdx.maps.tiled.tiledmap; import com.badlogic.gdx.maps.tiled.tiledmaptilelayer; import com.badlogic.gdx.maps.tiled.tiledmaptilelayer.cell; import com.badlogic.gdx.maps.tiled.tmxmaploader; import com.badlogic.gdx.maps.tiled.renderers.orthogonaltiledmaprenderer; public class game_screen implements screen{ private tiledmap map; private orthogonaltiledmaprenderer renderer; orthographiccamera camera; private static final int frame_cols = 4; // #1 private static final int frame_rows = 4; // #2 animation walkanimationup; // #3 animation walkanimationupidle; // #3 animation walkanimationdown; // #3 animation walkanimationdownidle; // #3 animation walkanimationleft; // #3 animation walkanimationleftidle; // #3 animation walkanimationright; // #3 animation walkanimationrightidle; // #3 cell cellright; int blockedright = 0; cell cellleft; int blockedleft = 0; cell cellup; int blockedup = 1; cell celldown; int blockeddown = 1; int cellx; int celly; int[] layers = {1,2,3}; texture walksheet; // #4 textureregion[] walkframesup; // #5 textureregion[] walkframesupidle; // #5 textureregion[] walkframesdown; // #5 textureregion[] walkframesdownidle; // #5 textureregion[] walkframesleft; // #5 textureregion[] walkframesleftidle; // #5 textureregion[] walkframesright; textureregion[] walkframesrightidle; int boundaryxleft = 0; int boundaryydown = 0; int boundaryxright = 6720; int boundaryyup = 4032; mygdxgame game; spritebatch spritebatch; // #6 textureregion currentframe; // #7 int spritex = 0; int spritey = 0; int newx = 0; int newy = 0; int lastkey = 0; int currentkey = 0; int speed; float statetime; // #8 boolean pause = false; tiledmaptilelayer layer; string collisionlayer; public game_screen(mygdxgame game) { this.game = game; tmxmaploader loader = new tmxmaploader(); map = loader.load("actualmap.tmx"); renderer = new orthogonaltiledmaprenderer(map); camera = new orthographiccamera(); camera.settoortho(false, 1920, 1080); camera.position.set(spritex,spritey, statetime); walksheet = new texture(gdx.files.internal("newsprite.png")); // #9 textureregion[][] tmp = textureregion.split(walksheet, walksheet.getwidth()/frame_cols, walksheet.getheight()/frame_rows); // #10 walkframesright = new textureregion[frame_cols * frame_rows]; walkframesrightidle = new textureregion[frame_cols * frame_rows]; walkframesleft = new textureregion[frame_cols * frame_rows]; walkframesleftidle = new textureregion[frame_cols * frame_rows]; walkframesup = new textureregion[frame_cols * frame_rows]; walkframesupidle = new textureregion[frame_cols * frame_rows]; walkframesdown = new textureregion[frame_cols * frame_rows]; walkframesdownidle = new textureregion[frame_cols * frame_rows]; collisionlayer = "collision"; speed = 2; ; int index = 0; (int = 0; < frame_rows; i++) { (int j = 0; j < frame_cols; j++) { walkframesright[index++] = tmp[2][j]; } } index = 0; (int = 0; < frame_rows; i++) { (int j = 0; j < frame_cols; j++) { walkframesrightidle[index++] = tmp[2][1]; } } index = 0; (int = 0; < frame_rows; i++) { (int j = 0; j < frame_cols; j++) { walkframesleft[index++] = tmp[1][j]; } } index = 0; (int = 0; < frame_rows; i++) { (int j = 0; j < frame_cols; j++) { walkframesleftidle[index++] = tmp[1][1]; } } index = 0; (int = 0; < frame_rows; i++) { (int j = 0; j < frame_cols; j++) { walkframesup[index++] = tmp[3][j]; } } index = 0; (int = 0; < frame_rows; i++) { (int j = 0; j < frame_cols; j++) { walkframesupidle[index++] = tmp[3][1]; } } index = 0; (int = 0; < frame_rows; i++) { (int j = 0; j < frame_cols; j++) { walkframesdown[index++] = tmp[0][j]; } } index = 0; (int = 0; < frame_rows; i++) { (int j = 0; j < frame_cols; j++) { walkframesdownidle[index++] = tmp[0][1]; } } walkanimationright = new animation(0.2f, walkframesright); // #11 walkanimationrightidle = new animation(0.2f, walkframesrightidle); // #11 walkanimationleft = new animation(0.2f, walkframesleft); // #11 walkanimationleftidle = new animation(0.2f, walkframesleftidle); // #11 walkanimationup = new animation(0.2f, walkframesup); // #11 walkanimationupidle = new animation(0.2f, walkframesupidle); // #11 walkanimationdown = new animation(0.2f, walkframesdown); // #11 walkanimationdownidle = new animation(0.2f, walkframesdownidle); // #11 spritebatch = new spritebatch(); // #12 statetime = 0f; // #13 } @override public void render(float delta) { layer = (tiledmaptilelayer) map.getlayers().get(collisionlayer); camera.update(); spritebatch.setprojectionmatrix(camera.combined); gdx.gl.glclearcolor(1, 1, 1, 1); gdx.gl.glclear(gl20.gl_color_buffer_bit); // #14 statetime += gdx.graphics.getdeltatime(); // #15 cellx = spritex/64; celly = spritey/64; cellup = layer.getcell(cellx, celly+1); celldown = layer.getcell(cellx, celly-1); cellright = layer.getcell(cellx+1, celly); cellleft = layer.getcell(cellx-1, celly); blockedup = integer.parseint((string) cellup.gettile().getproperties().get("blocked")); if(celly != 0) blockeddown = integer.parseint((string) celldown.gettile().getproperties().get("blocked")); if(cellx != 0) blockedleft = integer.parseint((string) cellleft.gettile().getproperties().get("blocked")); blockedright = integer.parseint((string) cellright.gettile().getproperties().get("blocked")); if(gdx.input.iskeypressed(input.keys.left) && spritex == newx && spritey == newy && spritex > boundaryxleft && blockedleft == 0) { lastkey = 1; newx-=64; currentkey = 1; } else if(gdx.input.iskeypressed(input.keys.right) && spritex == newx && spritey == newy && spritex < boundaryxright && blockedright == 0 ) { lastkey = 0; newx+=64; currentkey = 0; } else if(gdx.input.iskeypressed(input.keys.up) && spritey == newy && spritex == newx && spritey < boundaryyup && blockedup == 0) { lastkey = 2; newy+=64; currentkey = 2; } else if(gdx.input.iskeypressed(input.keys.down) && spritey == newy && spritex == newx && spritey > boundaryydown && blockeddown == 0 ) { lastkey = 3; newy-=64; currentkey = 3; } else if(spritex == newx && spritey == newy) { currentkey = 4; } if(gdx.input.iskeypressed(input.keys.down) && spritey == newy && spritex == newx && spritey > boundaryydown && blockeddown == 2 && lastkey == 3) { lastkey = 3; newy-=128; currentkey = 3; if(collisionlayer.equals("collision")) { collisionlayer = "inside"; layers[1] = 4; layers[2] = 4; } else if(collisionlayer.equals("inside")) { collisionlayer = "collision"; layers[1] = 2; layers[2] = 3; } } if(gdx.input.iskeypressed(input.keys.up) && spritey == newy && spritex == newx && spritey < boundaryyup && blockedup == 2 && lastkey == 2) { lastkey = 2; newy+=128; currentkey = 2; if(collisionlayer.equals("collision")) { collisionlayer = "inside"; layers[1] = 4; layers[2] = 4; } else if(collisionlayer.equals("inside")) { collisionlayer = "collision"; layers[1] = 2; layers[2] = 3; } } if(gdx.input.iskeypressed(input.keys.left) && lastkey != 1 && spritey == newy && spritex == newx ) { lastkey = 1; } if(gdx.input.iskeypressed(input.keys.right) && lastkey != 0 && spritey == newy && spritex == newx ) { lastkey = 0; } if(gdx.input.iskeypressed(input.keys.up) && lastkey != 2 && spritey == newy && spritex == newx ) { lastkey = 2; } if(gdx.input.iskeypressed(input.keys.down) && lastkey != 3 && spritey == newy && spritex == newx ) { lastkey = 3; } if(gdx.input.iskeyjustpressed(input.keys.escape)) { gdx.app.exit(); } if(spritex < newx) spritex+=(speed); if(spritex > newx) spritex-=(speed); if(spritey < newy) spritey+=(speed); if(spritey > newy) spritey-=(speed); if(lastkey == 0 && spritex != newx) {; currentframe = walkanimationright.getkeyframe(statetime, true); // #16 } else if(lastkey == 0 && spritex == newx && currentkey == 4) { currentframe = walkanimationrightidle.getkeyframe(statetime, true); // #16 } if(lastkey == 1 && spritex != newx) { currentframe = walkanimationleft.getkeyframe(statetime, true); // #16 } else if (lastkey == 1 && spritex == newx && currentkey == 4) { currentframe = walkanimationleftidle.getkeyframe(statetime, true); // #16 } if(lastkey == 2 && spritey != newy) { currentframe = walkanimationup.getkeyframe(statetime, true); // #16 } else if (lastkey == 2 && spritey == newy && currentkey == 4) { currentframe = walkanimationupidle.getkeyframe(statetime, true); // #16 } if(lastkey == 3 && spritey != newy) { currentframe = walkanimationdown.getkeyframe(statetime, true); // #16 } else if (lastkey == 3 && spritey == newy && currentkey == 4) { currentframe = walkanimationdownidle.getkeyframe(statetime, true); // #16 } camera.position.set(spritex, spritey, 0); renderer.setview(camera); renderer.render(layers);; spritebatch.begin(); spritebatch.draw(currentframe, spritex, spritey); // #17 spritebatch.end(); } @override public void dispose() { // todo auto-generated method stub spritebatch.dispose(); renderer.dispose(); map.dispose(); } @override public void resize(int width, int height) { // todo auto-generated method stub } @override public void pause() { // todo auto-generated method stub } @override public void resume() { // todo auto-generated method stub } @override public void hide() { // todo auto-generated method stub } @override public void show() { // todo auto-generated method stub } }
Comments
Post a Comment