Show Posts
|
|
Pages: [1]
|
|
8
|
Game Development / Newbie & Debugging Questions / NullPointerException at Slick2D Image constructor
|
on: 2011-12-03 18:21:56
|
Hey, I'm trying to create an image of a space ship that consist of different parts, but I'm getting a NullPointerException at the Image(int, int) constructor. Exception in thread "Client" java.lang.NullPointerException at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:1372) at org.newdawn.slick.opengl.InternalTextureLoader.createTextureID(InternalTextureLoader.java:106) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:359) at org.newdawn.slick.opengl.InternalTextureLoader.createTexture(InternalTextureLoader.java:343) at org.newdawn.slick.opengl.InternalTextureLoader.createTexture(InternalTextureLoader.java:329) at org.newdawn.slick.Image.<init>(Image.java:238) at net.aichix3.devrays.Ship.getSprite(Ship.java:32) at net.aichix3.devrays.Shipslot.<init>(Shipslot.java:29) at net.aichix3.devrays.Network$1.received(Network.java:74) at com.esotericsoftware.kryonet.Connection.notifyReceived(Connection.java:270) at com.esotericsoftware.kryonet.Client.update(Client.java:296) at com.esotericsoftware.kryonet.Client.run(Client.java:332) at java.lang.Thread.run(Unknown Source)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| static Image getSprite(ShipAspect a) { try { Image s = new Image(Game.i.get("ship" + a.id).getWidth() + 200, Game.i.get("ship" + a.id).getHeight() + 200); Graphics sg = s.getGraphics(); sg.drawImage(Game.i.get("ship" + a.id), 100, 100); sg.drawImage(Game.i.get("w1"), WEAPONS[1].x, WEAPONS[1].y); sg.flush(); return s; } catch (SlickException e) { e.printStackTrace(); return null; } } |
What's wrong with the code? =/
|
|
|
|
|
9
|
Game Development / Newbie & Debugging Questions / Re: URI is not hierarchical
|
on: 2011-11-29 20:45:27
|
I prefer to not create a txt with an image index. This does not seem to be very productive and slows down the developement. I finally created a data initialization that automatically checks if it is a jar or not during the runtime and chooses the correct way to load files, works perfect for me: 1 2 3 4 5 6 7 8
| try { if (Game.class.getResource("/" + Game.class.getName().replace('.', '/') + ".class").toString().startsWith("file")) loadFiles(); else loadResources(); } catch (Exception e) { e.printStackTrace(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| static void loadFiles() {
try { for (String n : new File(ClassLoader.getSystemResource("i").toURI()).list()) i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n)); } catch (URISyntaxException | SlickException e) { e.printStackTrace(); }
try { for (String n : new File(ClassLoader.getSystemResource("f").toURI()).list()) { if (n.endsWith("t")) { n = n.substring(0, n.indexOf('.')); f.put(n, new AngelCodeFont("f/" + n + ".fnt", "f/" + n + ".png")); } } } catch (URISyntaxException | SlickException e) { e.printStackTrace(); }
} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| static void loadResources() { try { Enumeration<JarEntry> en = new JarFile("gametest.jar").entries(); while (en.hasMoreElements()) { JarEntry n = (JarEntry) en.nextElement(); String name = n.getName(); if (name.startsWith("i") && name.indexOf('.') > -1) i.put(name.substring(2, name.indexOf('.')), new Image(name)); if (name.endsWith("fnt")) f.put(name.substring(2, name.indexOf('.')), new AngelCodeFont(name, name.substring(0, name.indexOf('.')) + ".png")); } } catch (IOException | SlickException e) { e.printStackTrace(); } } |
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Re: URI is not hierarchical
|
on: 2011-11-29 15:14:23
|
Debug code: 1 2 3 4 5
| try { System.err.println(ClassLoader.getSystemResource("i").toURI().toString()); } catch (URISyntaxException e1) { e1.printStackTrace(); } |
Result in Eclipse: file:/D:/Users/Dario/Desktop/space/Devrays/bin/iResult as runnable jar: jar:file:/D:/Users/Dario/Desktop/gametest.jar!/i
|
|
|
|
|
12
|
Game Development / Newbie & Debugging Questions / Re: URI is not hierarchical
|
on: 2011-11-29 14:45:56
|
Ah, thanks, the actual trigger is Game.java:47. 1 2 3 4 5 6 7
| try { for (String n : new File(ClassLoader.getSystemResource("i").toURI()).list()) i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n)); i.put("clickable1", i.get("clickable0").getFlippedCopy(true, false)); } catch (URISyntaxException e) { e.printStackTrace(); } |
I'm still looking for help with bypass that exception.
|
|
|
|
|
13
|
Game Development / Newbie & Debugging Questions / URI is not hierarchical
|
on: 2011-11-29 14:06:50
|
Hey, I got a problem with runnable jars that I export with Eclipse. VM Call: java -Djava.library.path=D:\Users\Dario\Desktop\native\windows -jar gametest.jar Console log:  Exception points to: 1 2 3 4 5 6 7 8 9 10 11 12
| public static void main(String[] args) { try { AppGameContainer app = new AppGameContainer(new Game()); app.setIcon("i/default.png"); app.setDisplayMode(1024, 768, false); app.setTargetFrameRate(30); app.setMouseGrabbed(true); app.start(); } catch (SlickException e) { e.printStackTrace(); } } |
Everything is working fine in Eclipse. Any suggestions? =)
|
|
|
|
|
16
|
Game Development / Game Mechanics / OO Games - General theory
|
on: 2011-11-21 23:59:47
|
Hey, I am thinking much about modeling an efficient game the last time. I'm using Java since six months and making games since about 5 years, but this is the first time I want to realize a whole game in Java. I planned a Space-Shooter MMORPG with Java7, Slick2D and Kryonet.  The only problem that I have right know is that I dont know how to switch between main menu, login screen, option panel, pause screen and The Game. This is some of my current code: 1 2 3
| static HashMap<String, Image> i = new HashMap<String, Image>(); static HashMap<String, AngelCodeFont> f = new HashMap<String, AngelCodeFont>(); static ArrayList<Entity> e = new ArrayList<Entity>(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| @Override public void init(GameContainer c) throws SlickException { Network.load(); Network.tcp(new Start()); try { for (String n : new File(ClassLoader.getSystemResource("i").toURI()).list()) i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n)); i.put("clickable1", i.get("clickable0").getFlippedCopy(true, false)); } catch (URISyntaxException e) { e.printStackTrace(); }
try { for (String n : new File(ClassLoader.getSystemResource("f").toURI()).list()) { if (n.endsWith("t")) { n = n.substring(0, n.indexOf('.')); f.put(n, new AngelCodeFont("f/" + n + ".fnt", "f/" + n + ".png")); } } } catch (URISyntaxException e) { e.printStackTrace(); }
start(); } |
1 2 3 4 5 6 7 8
| void start() { Interface.create(); Cursor.load(); Player p = new Player(Ship.SHIPID_SHUTTLE, 5, 5); e.add(p); } |
1 2 3 4 5 6 7 8 9
| @Override public void update(GameContainer c, int delta) throws SlickException { Interface.run(); for (ListIterator<Entity> n = e.listIterator(e.size()); n.hasPrevious();) { if (!n.previous().run()) n.remove(); } Cursor.run(); } |
1 2 3 4 5 6 7 8
| @Override public void render(GameContainer c, Graphics g) throws SlickException { for (Entity n : e) { n.render(); } Interface.render(); Cursor.render(); } |
This works fine, but what should I do to only run an instance of a MainMenu class at first? I could create an int gamestate and do a switch(gamestate) at render() and update(), but I would come up with an undynamic clump of bad written code. I'd be thankful for every approach and every source improvements.
|
|
|
|
|
17
|
Game Development / Networking & Multiplayer / Re: [Kryonet] Client Listener does not react
|
on: 2011-11-21 14:04:54
|
You should name your class to something else than Connection, because at the moment the received method doesn't override anything because Listener class doesn't obviously have corresponding method for receiving your Connection objects  This is why suppressing warnings is bad if you don't know what they mean. Damn, thank you, that was right, the name Connection is already used by a parameter class.  Everything works fine now, thank you guys!
|
|
|
|
|
18
|
Game Development / Networking & Multiplayer / Re: [Kryonet] Client Listener does not react
|
on: 2011-11-21 07:35:54
|
Could you remove the quotes from around the code?
Why are you suppressing the "unused" warning in the client listener?
Probably to suppress warning about the unused Connection object? Try to add some System.out.println()s in the received method, BEFORE the instanceof. That will help you detect if you're actually receiving anything at all. Eclipse said that I should remove method reiceive() because " The method received(Connection c, Object o) from type new Listener(){} is never used locally". Looks like the GC takes something away from me. I updated the code in my first post.
|
|
|
|
|
19
|
Game Development / Networking & Multiplayer / [Kryonet] Client Listener does not react
|
on: 2011-11-21 01:10:03
|
Hey, I have started using the Kryonet lib and I have some trouble with the network communication. I followed the kryonet instruction, but either the server does not send a package or the client does not receive anything. Client: 1 2
| if (!Connection.load()) System.exit(0); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public class Connection {
static Client client; static boolean load() {
try {
client = new Client(); client.start(); client.connect(5000, "localhost", 54555, 54777);
Kryo kryo = client.getKryo(); kryo.register(Request.class); kryo.register(Response.class);
Request request = new Request(); request.text = "Here is the request!"; client.sendTCP(request);
client.addListener(new Listener() { @SuppressWarnings("unused") public void received(Connection c, Object o) { Sys.alert("A", "B"); if (o instanceof Response) { Response response = (Response) o; Out.say(response.text); } } });
return true;
} catch (Exception e) { e.printStackTrace(); return false; } }
} |
Server: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| Server server = new Server(); server.start(); server.bind(54555, 54777); Kryo kryo = server.getKryo(); kryo.register(Request.class); kryo.register(Response.class);
server.addListener(new Listener() { public void received(Connection c, Object o) { if (o instanceof Request) { Request request = (Request) o; System.out.println(request.text); Response response = new Response(); response.text = "Thanks!"; System.out.println(c.sendTCP(response)) } } }); |
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|