Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: NullPointerException at Slick2D Image constructor on: 2011-12-08 20:19:58
I bypassed Image.getGraphics() by using a static Graphics instance,
this way is quite fast. Smiley
2  Game Development / Newbie & Debugging Questions / Re: NullPointerException at Slick2D Image constructor on: 2011-12-05 00:13:10
It would be nice to use this method every frame to support different scalings for smaller screens.
3  Game Development / Newbie & Debugging Questions / Re: NullPointerException at Slick2D Image constructor on: 2011-12-04 21:21:01
Does nobody have some optimizations for the above method? Creating two sprites decreases my FPS rate from ~ 100 to 6 FPS.
4  Game Development / Newbie & Debugging Questions / Re: NullPointerException at Slick2D Image constructor on: 2011-12-04 00:44:41
Oh, another thing:
Is there a way to speed up my method?
5  Game Development / Newbie & Debugging Questions / Re: NullPointerException at Slick2D Image constructor on: 2011-12-03 23:48:45
Ok, every ship has synchronized boolean isUptodate now which will be set to true in the network thread and evaluated in the next frame of the Slick thread. I hope the synchronized-modifer is enough to prevent exceptions because of concurrent using.

Thanks for your help. Smiley
6  Game Development / Newbie & Debugging Questions / Re: NullPointerException at Slick2D Image constructor on: 2011-12-03 20:55:24
The network thread does not have to talk to the slick thread at all, at least not yet.
I currently use CopyOnWriteArrayList to prevent concurrent using of my variables.
7  Game Development / Newbie & Debugging Questions / Re: NullPointerException at Slick2D Image constructor on: 2011-12-03 20:06:55
Ah, thanks. Smiley
The ship generation method is called by the network thread - after the server notifies the client about ship changes.
How could the network thread tell the Slick thread to call getSprite() ?
8  Game Development / Newbie & Debugging Questions / NullPointerException at Slick2D Image constructor on: 2011-12-03 17: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.

Quote
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); // Ship.java:32 // a.id == 3 // Game.i.get("ship3") != null
// new Image(200, 200) does not work too      
  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 19: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();
      }
   }
10  Game Development / Newbie & Debugging Questions / Re: URI is not hierarchical on: 2011-11-29 16:20:24
Jar entry listing works in theory, but this would mean that I can't execute my projects through Eclipse anymore.
Is there no way for both Eclipse debugging and exportet .jars? =/
11  Game Development / Newbie & Debugging Questions / Re: URI is not hierarchical on: 2011-11-29 14: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/i

Result 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 13: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()) // LINE 47 // For every image file in src\i
           i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n)); // load and put to ArrayList<Image> i
        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 13:06:50
Hey,
I got a problem with runnable jars that I export with Eclipse.

VM Call:
Quote
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(); // LINE 31
     } catch (SlickException e) {
         e.printStackTrace();
      }
   }


Everything is working fine in Eclipse. Any suggestions? =)
14  Game Development / Game Mechanics / Re: OO Games - General theory on: 2011-11-27 02:53:32
The already implemented transitions seems to be sufficient for my purposes, thanks. Smiley
15  Game Development / Game Mechanics / Re: OO Games - General theory on: 2011-11-24 23:20:22
Ah, thanks, that's what I searched for. Smiley



Is there any tutorial or example that shows how to create transitions?
16  Game Development / Game Mechanics / OO Games - General theory on: 2011-11-21 22: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>(); // images
  static HashMap<String, AngelCodeFont> f = new HashMap<String, AngelCodeFont>(); //fonts
  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 // entities
  public void init(GameContainer c) throws SlickException {
     
      Network.load(); // Init Kryonet
     Network.tcp(new Start()); //send first packet to check for updates

      try { // load all pictures found in the image directory
        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 { // load all ACFonts found in the font directory
        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();
      }

      // (main menu)
     // (login screen)

      start(); // game start

   }
1  
2  
3  
4  
5  
6  
7  
8  
void start() {
      Interface.create(); //create instances of buttons
     Cursor.load(); // load cursor sprite

      Player p = new Player(Ship.SHIPID_SHUTTLE, 5, 5); // create new shuttle at 5, 5
     e.add(p); // make shuttle runnable

   }
1  
2  
3  
4  
5  
6  
7  
8  
9  
@Override
   public void update(GameContainer c, int delta) throws SlickException {
      Interface.run(); // update all components
     for (ListIterator<Entity> n = e.listIterator(e.size()); n.hasPrevious();) {
         if (!n.previous().run()) // boolean(), so entities can say that they want to get removed
           n.remove();
      }
      Cursor.run(); // update cursor
  }
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 13: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 Smiley 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. Smiley
Everything works fine now, thank you guys!
18  Game Development / Networking & Multiplayer / Re: [Kryonet] Client Listener does not react on: 2011-11-21 06: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 00: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"); // never called!
              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); // Here is the request

                  Response response = new Response();
                  response.text = "Thanks!";
                  System.out.println(c.sendTCP(response)) // 11;
              }
            }
         });


Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (23 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (32 views)
2014-08-08 02:01:56

Norakomi (42 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 22:40:00

List of Learning Resources
by SilverTiger
2014-08-06 07:33:27

Resources for WIP games
by CogWheelz
2014-08-02 04:20:17

Resources for WIP games
by CogWheelz
2014-08-02 04:19:50

List of Learning Resources
by SilverTiger
2014-08-01 04:29:50

List of Learning Resources
by SilverTiger
2014-08-01 04:26:06

List of Learning Resources
by SilverTiger
2014-07-31 23:54:12

HotSpot Options
by dleskov
2014-07-08 13:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!