Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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] 2
1  Game Development / Newbie & Debugging Questions / Re: Playing sounds for my game on: 2014-05-11 14:44:41
Ok, now I've got it working. There is one thing that confuses me though. If I play a music track in the background and then play a short sound (like a gunshot) with another thread then the volume of the music goes down to about a third of the original volume even after the short sound has ended. Anyone have an idea about why this happens? I'll put my code for the "playShortSound" method below. The method that plays background music is the same but in a while loop to keep it repeating.

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  
41  
42  
43  
44  
45  
46  
private void playSound(String filename){
        System.out.println("Going to play the sound " + filename);
        try {
            URL url = SoundPlayer.class.getResource("/resources/sound/"+filename);
            audioStream = AudioSystem.getAudioInputStream(url);
             //musicStream = new AudioInputStream(SoundPlayer.class.getResourceAsStream("/resources/sound/"+path), format, length);
        } catch (Exception e){
             e.printStackTrace();
            //System.exit(1);
        }

         audioFormat = audioStream.getFormat();

         DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
         try {
             sourceLine = (SourceDataLine) AudioSystem.getLine(info);
             sourceLine.open(audioFormat);
         } catch (LineUnavailableException e) {
             e.printStackTrace();
             //System.exit(1);
        } catch (Exception e) {
             e.printStackTrace();
             //System.exit(1);
        }

         sourceLine.start();

         int nBytesRead = 0;
         byte[] abData = new byte[BUFFER_SIZE];
         while (nBytesRead != -1) {
             try {
                 nBytesRead = audioStream.read(abData, 0, abData.length);
             } catch (IOException e) {
                 e.printStackTrace();
             }
             if (nBytesRead >= 0) {
                 @SuppressWarnings("unused")
                 int nBytesWritten = sourceLine.write(abData, 0, nBytesRead);
             }
         }

         sourceLine.drain();
         sourceLine.close();
         
         System.out.println("Done playing the sound " + filename);
     }
2  Game Development / Newbie & Debugging Questions / Playing sounds for my game on: 2014-05-11 11:56:03
I want to play some sounds for my game. In my "src" folder I have a "resource" folder which contains a folder "sound" contining WAV-files. I want to read and play those. Currently my playing mathod looks like this:

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 void playLoopedSound() {
         do{//A do-while-loop to keep playing the sound over and over
           try {
                musicStream = (AudioInputStream) SoundPlayer.class.getResourceAsStream("/resources/sound/"+path);
            } catch (Exception e){
                e.printStackTrace();
            }

            musicFormat = musicStream.getFormat();

            DataLine.Info info = new DataLine.Info(SourceDataLine.class, musicFormat);
            try {
               musicSourceLine = (SourceDataLine) AudioSystem.getLine(info);
               musicSourceLine.open(musicFormat);
            } catch (LineUnavailableException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }

            musicSourceLine.start();

            int nBytesRead = 0;
            byte[] abData = new byte[BUFFER_SIZE];
            while (running && nBytesRead!=-1) {
                try {
                    nBytesRead = musicStream.read(abData, 0, abData.length);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (nBytesRead >= 0) {
                    @SuppressWarnings("unused")
                    int nBytesWritten = musicSourceLine.write(abData, 0, nBytesRead);
                }
            }

            musicSourceLine.drain();
            musicSourceLine.close();
         }while(running);
     }


This code gives me the following Exception:
1  
2  
3  
4  
5  
6  
java.lang.ClassCastException: java.io.BufferedInputStream cannot be cast to javax.sound.sampled.AudioInputStream
   at project.sound.SoundPlayer.playLoopedSound(SoundPlayer.java:72)
   at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-1" java.lang.NullPointerException
   at project.sound.SoundPlayer.run(SoundPlayer.java:78)
   at java.lang.Thread.run(Unknown Source)


I would really like to have some help. If anyone has a method that works for this I'd love to see it. If it's complicated to do this I wouldn't mind a method that plays WAV-files that lie in a folder next to the JAR-file instead of inside it.

I don't know if this helps but here's the method I use to load images from a folder which lies next to the "sound" folder in the "resource" folder in the JAR-file. It works perfectly so maybe it can help you imagine how my folders are set up.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public static BufferedImage loadImage(String path){
      URL myImageURL = FileHandler.class.getResource("/resources/images/" + path);
      try {
         BufferedImage myImage = ImageIO.read(myImageURL);
         return myImage;
      } catch (IOException e) {
         e.printStackTrace();
         System.out.println("ERROR@FileHandler.loadImage(String path) - IOException with path: " + path);
         return null;
      } catch(IllegalArgumentException e){
         e.printStackTrace();
         System.out.println("ERROR@FileHandler.loadImage(String path) - IllegalArgumentException with path: " + path);
         return null;
      }
   }
3  Game Development / Newbie & Debugging Questions / Re: Loading Native files so that LWJGL can be used on: 2014-04-30 11:07:28
I see. Guess I'll just have to leave it like that and write in the "readme" that you need those files for it to work
4  Game Development / Newbie & Debugging Questions / Re: Editing a text-file stored inside a JAR on: 2014-04-30 11:06:14
@CodeHead
URI folderLocation = new URL(appLocation, "My/Folder/Location").toURI();
This worked while in Eclipse, and created new Folders in the "bin". But once exported it didn't work and it instead gave me
"rsrc:My/Folder/Location/test.txt"
Do you have any idea why this happens?
5  Game Development / Newbie & Debugging Questions / Loading Native files so that LWJGL can be used on: 2014-04-30 09:03:15
I'm using the following method to load the native files from a folder "nat" next to the JAR file.

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  
public static void load() {
         
         String system = System.getProperty("os.name");
         
         String path = null;
         path = new File("nat").getAbsolutePath();

         if(path == null) {
            System.out.println("Couldn't load natives!");
            return;
         }

         path += "\\";
         
         if (system.contains("Windows")) {
           
             System.setProperty("org.lwjgl.librarypath", path + "Windows");
         }
         else if (system.contains("Mac")) {
             System.setProperty("org.lwjgl.librarypath", path + "Mac");
         }
         else if (system.contains("Linux")) {
             System.setProperty("org.lwjgl.librarypath", path + "Linux");
         }
         
      }


If possible, I'd like to be able to put that folder inside the JAR and read it from there so that the program doesn't rely on that folder being copied along with the JAR file. I've been reading images and text files from within a JAR with the following methods but I can't seem to adapt that to reading natives.

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  
   public BufferedImage loadImage(String path){
      URL myImageURL = FileLoader.class.getResource("/res/" + path);
      try {
         BufferedImage myImage = ImageIO.read(myImageURL);
         return myImage;
      } catch (IOException e) {
         e.printStackTrace();
         System.out.println("ERROR@FileHandler.loadImage(String path) - IOException with path: " + path);
         return null;
      } catch(IllegalArgumentException e){
         e.printStackTrace();
         System.out.println("ERROR@FileHandler.loadImage(String path) - IllegalArgumentException with path: " + path);
         return null;
      }
   }
   
   public String[] loadText(String path){
      InputStream mySettingsStream = FileLoader.class.getResourceAsStream("/res/"+path);
      String mySettingsString = "null";
      StringBuilder build = new StringBuilder();
      int i = 0;
      try {
         while((i = mySettingsStream.read()) != -1) {
            build.append((char)i);
         }
         mySettingsString = build.toString();
         return mySettingsString.split("\r\n");
      } catch (IOException e) {
         e.printStackTrace();
         return null;
      }
   }
6  Game Development / Newbie & Debugging Questions / Re: Editing a text-file stored inside a JAR on: 2014-04-29 15:05:08
Maybe that "read only" is the reason why this doesn't work even though I get no errors/exceptions with my code.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
   public void write(String path, String[] lines){
      if(path==null || lines==null){return;}
      URL url = FileLoader.class.getResource("/res/" + path);
      System.out.println("The URL we got is " + url.toString());
      try {
         File file = new File(url.toURI());
         PrintWriter out = new PrintWriter(file);
         for(int i = 0; i < lines.length; i++){
            System.out.println("Appending...");
            out.append(lines[i]);
            out.append("\r\n");  
         }
         out.flush();
         out.close();
      } catch (IOException e) {
         System.err.println("Failed to write to file");
         e.printStackTrace();
      } catch (URISyntaxException e) {
         System.err.println("Failed to write to file");
         e.printStackTrace();
      }
   }


In that case I just have one question. Storing save information outside of the JAR file is ok but I have a wish there. Instead of having a dozen files in the same folder as the JAR, I'd like to create a folder next to the JAR and save them in there. Is there a simple way to check if there is a folder with a certain name next to the JAR and, in case it doesn't exist, creating it?
7  Game Development / Newbie & Debugging Questions / Editing a text-file stored inside a JAR on: 2014-04-29 14:22:47
Ok, I have a .txt file stored inside a folder "res" inside my JAR-file. I can read from that file with the following method.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   public String[] loadText(String path){
      InputStream mySettingsStream = FileLoader.class.getResourceAsStream("/res/"+path);
      String mySettingsString = "null";
      StringBuilder build = new StringBuilder();
      int i = 0;
      try {
         while((i = mySettingsStream.read()) != -1) {
            build.append((char)i);
         }
         mySettingsString = build.toString();
         return mySettingsString.split("\r\n");
      } catch (IOException e) {
         e.printStackTrace();
         return null;
      }
   }


However, I want to be able to store changes I've made to the data in that file and I can't figure out how to do that. I tried using an OutputStreamWriter with a URL (as you can see below) but it caused a "java.net.UnknownServiceException: protocol doesn't support output" so I clearly need something else.
If possible I want to even be able to create a new .txt file at the location in case one with the name from path doesn't exist.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   public void write(String path, String[] lines){
      if(path==null || lines==null){return;}
      URL url = FileLoader.class.getResource("/res/" + path);
      try {
         URLConnection connection = url.openConnection();
         connection.setDoOutput(true);
         OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
         for(int i = 0; i < lines.length; i++){
            out.write(lines[i]);
         }
         out.close();
      } catch (IOException e) {
         System.err.println("Failed to write to file");
         e.printStackTrace();
      }
   }


Anyone have any ideas?
I know that it might not be the best idea to mess around with changing and creating files inside a JAR file but it'd be great if I could do it safely. At the very least I'd like to have the ability to edit text files in there.
8  Game Development / Newbie & Debugging Questions / Re: Reading files within an Executeable JAR file on: 2014-04-29 08:11:25
Thanks everyone for your help.
Does anyone happen to know how to write a text file to the same place as I'm been loading them from (the "res" folder inside the JAR)? It would be nice to be able to save a game easily.
9  Game Development / Newbie & Debugging Questions / Re: Reading files within an Executeable JAR file on: 2014-04-28 10:52:03
@orogamo
THANK YOU!! It works like a charm. The only files I need to load in right now is text and image files so your solution covers everything. Later I'll need to be able to do the same with music files (WAV files) and hopefully I'll be able to adapt this to load those. I know how to play them if I just get a Stream open to them so if you have a particular way of opening a stream for music I'd be very happy.
10  Game Development / Newbie & Debugging Questions / Reading files within an Executeable JAR file on: 2014-04-28 08:55:44
I have been working a lot to learn how to load files that lie within the JAR file, but I just can't get it working!!
No guide I'm trying works and I'm getting desperate. I'll put an example of how the JAR file is set up below, could anyone tell me how to load the image "Star.jpg" please?

1  
2  
3  
4  
5  
6  
7  
8  
folder
   Loader.jar
      package
         Loader.class      <- The running code
      META-INF
         MANIFEST.MF
      resources
         Star.jpg      <- the image I want to load


If someone could give me a full method that can do this instead of saying "use this _____" I'd be very grateful
11  Game Development / Newbie & Debugging Questions / Re: Creating a simple AI for an enemy NPC on: 2014-04-27 01:06:53
@Gibbo3771
Yes, it does make a lot of sense. I feel more confident with the "head towards the player when it's in a certain range" than I do with the "jump before the obstacle and keep moving forward" but I hope I'll be able to get it done.
If you have more tips, or the time to go in depth about it, you're most welcome to comment again.
12  Game Development / Newbie & Debugging Questions / Re: Creating a simple AI for an enemy NPC on: 2014-04-26 20:55:53
Well, I want them to at least be able to notice if there is an obstacle in their way and in that case I want them to try and jump over it.
They will also use ranged attacks and I don't want them to just shoot blindly when they have no chance of hitting me.
If you have a link to some webpage that gives tips to creating AI I'd be very grateful
13  Game Development / Newbie & Debugging Questions / Creating a simple AI for an enemy NPC on: 2014-04-25 22:00:41
I'm doing a 2D platform game (think Super Mario) and I need to make an AI that can control my NPCs. It would be quite boring if nothing ever attacked you after all.
However, I have absolutely no idea how to do something like that, I don't know first thing about AI. However what I need is guing to be quite simple so if I could just get some tips to get me started I think I can make it work.
14  Game Development / Newbie & Debugging Questions / Re: Using files in META-INF on: 2014-04-24 15:01:01
Ok, I got it working.
I can load an image like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public BufferedImage loadImage(String path){
      java.net.URL imgURL = getClass().getResource(path);
      if(imgURL != null){
         try {
            return ImageIO.read(imgURL);
         } catch (IOException e) {
            e.printStackTrace();
            return null;
         }
      }
      else{
         System.err.println("Couldn't find file: " + path);
           return null;
      }
   }
15  Game Development / Newbie & Debugging Questions / Re: Using files in META-INF on: 2014-04-24 14:08:02
@Grunnt
I tried it. Afraid it didn't work   Sad
This has turned out to be a lot harder than I thought it would be
16  Game Development / Newbie & Debugging Questions / Re: Using files in META-INF on: 2014-04-24 13:01:18
@junkdog
I'm sorry. First of all I don't quite understand that code you linked to and also I'm not interested in the Manifest file. I want to get, say, an image "ball.png" which lies in the META-INF map (or anywhere else in the JAR file)
I use the following code to load Native files from a folder which lies parallel to the JAR file (they are in the same folder). Let's say I want to move that "nat"-folder into the JAR file so that I only have to keep track of one file

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  
public static void load() {
         
         String system = System.getProperty("os.name");
         
         String path = null;
         path = new File("nat").getAbsolutePath();         //This here is where the path into
                                                          //the folder is set right?

         if(path == null) {
            System.out.println("Couldn't load natives!");
            return;
         }

         path += "\\";
         
         if (system.contains("Windows")) {
           
             System.setProperty("org.lwjgl.librarypath", path + "Windows");
         }
         else if (system.contains("Mac")) {
             System.setProperty("org.lwjgl.librarypath", path + "Mac");
         }
         else if (system.contains("Linux")) {
             System.setProperty("org.lwjgl.librarypath", path + "Linux");
         }
         
      }
17  Game Development / Newbie & Debugging Questions / Using files in META-INF on: 2014-04-24 11:55:26
I can put a file into the META-INF folder easily (just change the type to ZIP and then move it there) but how should I do to load the file in the program?
I'm fairly inexperienced with loading files and don't even know how to load something from a folder lying at the same place as the JAR file, is there a difference to this compared to loading something from the META-INF?
If possible I'd like to be able to put folders in the META-INF folder and then load files from those folders (it'd make file handling a bit easier for me)
18  Game Development / Newbie & Debugging Questions / Problems with generating subclasses on: 2014-04-23 14:18:22
I have an abstract class "Spell" and lets all spells extend that one. This is for the sake of being able to keep different spells in a single array (like, if your character knows 3 spells and he learns a new one I don't want to have to rewrite the code to make it possible for him to have that).
Now, the subclasses of Spell has two "states" (I think you can call it that); Active & Inactive. In short, the player has one of every type of Spell he can use in his Array as an Inactive, but when he casts a spell I create a new instance of this spell, completely unrelated to the original Inactive one, which is then handled by the "Active Spells Handler".
The problem I have is when it comes to creating a new spell, I don't know how to make it create the same type of class. If I cast FireBlast I want to create a new FireBlast Object but with the same row of code I want to be able to create an IceLance Object if that was the spell I tried to cast. I know how to check if an object of type Spell is an instance of FireBlast, but I'd rather not have to use a long set of if:s to first find the type of subclass it is and then make a direct creation of this subclass.

I hope you can understand what I'm trying to say
19  Game Development / Newbie & Debugging Questions / Re: Problem with getting LWJGL to work outside of Eclipse on: 2014-04-17 13:39:13
@trollwarrior1
I'll say what the guy who made that other comment said: "You are a saint! Thank you so much!"!!
Just one new line of coad, calling that function, and all of a sudden it works (as long as you have that "nat" folder of course =)
20  Game Development / Newbie & Debugging Questions / Re: Problem with getting LWJGL to work outside of Eclipse on: 2014-04-17 11:15:11
@trollwarrior1
I did as you told me to and I did indeed get an error message. However I don't quite understand what it means. Could you help me?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
C:\Users\Admin>java -jar TestOpenGL.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Mathod)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
   at java.lang.ClassLoader.loadLibrary(Unknown Source)
   at java.lang.Runtime.loadLibrary0(Unknown Source)
   at java.lang.System.loadLibrary(Unknown Source)
   at org.lwjgl.Sys$1.run(Sys.java:73)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
   at org.lwjgl.Sys.loadLibrary(Sys.java:95)
   at org.lwjgl.Sys.<clinit>(Sys.java:112)
   at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
   at OpenGL_Example.main(OpenGL_Example.java:26)
   ... 5 more
21  Game Development / Newbie & Debugging Questions / Problem with getting LWJGL to work outside of Eclipse on: 2014-04-17 09:35:25
I have the problem that when I work in Eclipse I can get a window to open as it should but for some reason I can't get it to start once I've exported the program to a JAR-file. I made a very simple example where I only draw a single image on the center of the screen and tried that. It worked in Eclipse and it didn't work once exported (in a way I'm glad that is so, it shows the problem is quite basic and not a huge error in my other program).
I've added in the code here so that you can see. It works in Eclipse, but not when exported.

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  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.ARBDebugOutput.*;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;

import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ARBDebugOutputCallback;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.PixelFormat;


public class OpenGL_Example {

   public static void main(String[] args) {
      try {
         //Display.setDisplayMode(new DisplayMode(600, 400));
        Display.setDisplayModeAndFullscreen(Display.getDesktopDisplayMode());
         Display.create(new PixelFormat(), new ContextAttribs().withDebug(true));
         //Display.setVSyncEnabled(true);
        if(GLContext.getCapabilities().GL_ARB_debug_output){
            glDebugMessageCallbackARB(new ARBDebugOutputCallback());
         }
      } catch (LWJGLException e) {
         e.printStackTrace();
      }
     
      BufferedImage image = null;
     
      try {
         image = ImageIO.read(new File("BucketKitties.jpg"));   //Just your average cat image
     } catch (IOException e) {
         e.printStackTrace();
      }
     
      int width = image.getWidth(), height = image.getHeight();
      int[] pixels = image.getRGB(0, 0, width, height, new int[width*height], 0, width);
     
      ByteBuffer data = BufferUtils.createByteBuffer(3*width*height);
      //System.out.println(data);
     for(int i = 0; i < pixels.length; i++){
         int pixel = pixels[i];
         data.put((byte) ((pixel >> 16) & 0xFF));     // Red component
           data.put((byte) ((pixel >> 8) & 0xFF));      // Green component
           data.put((byte) (pixel & 0xFF));          // Blue component
     }
      //System.out.println(data);
     data.flip();      //Sets the Reading Marker to the start of the buffer
     //System.out.println(data);
     
      int texture = glGenTextures();
      glBindTexture(GL_TEXTURE_2D, texture);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
     
      //We don't need different sized images for this
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     
      glEnable(GL_TEXTURE_2D);
     
     
      while(!Display.isCloseRequested()){
         
         glClearColor(0, 0, 0, 0);
          glClear(GL_COLOR_BUFFER_BIT);
         
          glMatrixMode(GL_PROJECTION);   //Loads the Projection-matrix
         glLoadIdentity();   //Resets the projection-matrix
         //Sets a coordinate system where one pixel on the screen equals one coordinate
         glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -1, 1);  
         
          glMatrixMode(GL_MODELVIEW);   //The "Camera Position Matrix"
         glLoadIdentity();  
          glTranslatef(Display.getWidth()/2, Display.getHeight()/2, 0);   //We want to draw with the center of the screen as (0, 0)
         
          glBegin(GL_QUADS);
          {
             glColor3f(1, 1, 1);
             glTexCoord2f(0, 0);
             glVertex2f(-250, -250);
             
             //glColor3f(0, 1, 0);
            glTexCoord2f(1, 0);
             glVertex2f(250, -250);
             
             //glColor3f(0.5f, 0.5f, 0.5f);
            glTexCoord2f(1, 1);
             glVertex2f(250, 250);
             
             //glColor3f(0, 0, 1);
            glTexCoord2f(0, 1);
             glVertex2f(-250, 250);
          }
          glEnd();
         
         Display.sync(100);
         Display.update();
      }
      Display.destroy();
      JOptionPane.showMessageDialog(null, "Complete!");
   }

}
22  Game Development / Newbie & Debugging Questions / Re: Export from Eclipse causes trouble on: 2014-04-17 08:46:28
@trollwarrior1
I'm terribly sorry but I'm afraid I don't under stand what you mean. I don't know if I load any files with .internal (I don't even know what that is).
At least I have now been able to determine that the file is loaded as it should be and that the problem comes when I try to run the program.
23  Game Development / Newbie & Debugging Questions / Re: Export from Eclipse causes trouble on: 2014-04-17 08:32:48
I'm afraid it's hard for me to check where it goes wrong. I have notifications right before and after I load the serialization-file and as I said they pop up perfectly when running in Eclipse but only the one before seems to pop up when I run it after exporting it
24  Game Development / Newbie & Debugging Questions / Export from Eclipse causes trouble on: 2014-04-16 11:45:24
I'm using LWJGL to make a game.
Now I have a demo version that works perfectly but when I try to export it into a runnable jar file that file doesn't work.
I am using Serializable to store the state I need it to start in, which as I said works perfectly when started in Eclipse.
One thing that I noticed is that when I try to export it I get a warning message I have never seen before, maybe that is the reason? The message says as follows:
----------------------------------------------------------------------------
This operation repacks referenced libraries.
Please review the licenses associated with libraries you wish to reference to
make sure you are able to repack them using this application. Note also that
this operation does not copy signature files from original libraries to the
generated JAR file.
----------------------------------------------------------------------------
This error message did not appear if I changed the export setting from "Extract required libraries into the generated JAR" to "Package required libraries into generated JAR" but it made no difference. The program still didn't work.
At least it seems like it didn't crash, using the Task Manager it's possible to see that the java virtual machine is running until you stop it and it doesn't say that it's not answering so it shouldn't be completely crashed down.

Anyone has some ideas?
25  Game Development / Newbie & Debugging Questions / Identifying Subclasses on: 2014-04-15 10:30:08
I am making a simple 2D platform game and I have run into a slight problem with the Spells I want the player and NPCs to use.
I have an abstract class Spell and a set of subclasses extending Spell. These subclasses indicate the element of the spell, so one subclass might be Fire_Spell. I want to be able to receive a Spell and do something like
1  
2  
3  
if(spell.getClass() == Fire_Spell){
     doStuff();
}

But I can't figure out how to identify if spell is a certain subclass since whenever I try to compare the instance of Spell I have (which will never really be a Spell, always one of the subclasses of Spell) I just can't find a way that doesn't either end in an error or which gives a faulty answer.

I have tried something like "attack.isAssignableFrom(Fire_Spell)" and "attack.getClass().isAssignableFrom(Fire_Spell)" but those just say that "Fire_Spellcannot be resolved to a variable" so I wonder what I'm doing wrong.
26  Game Development / Newbie & Debugging Questions / Re: Listening to Keyboard while using OpenGL on: 2014-04-10 06:33:54
Thank you Agent.
Now it works perfectly and as a bonus I can even use it the same way as that GameCore you helped me write (with a boolean[])
27  Game Development / Newbie & Debugging Questions / Re: Listening to Keyboard while using OpenGL on: 2014-04-09 21:33:05
Hello again!

I got it working and all that now but there is one problem I have.
The Keyboard doesn't seem to generate any Events when you press the arrow-keys. It works for all letters and such but not for the arrows.
Since I'm making a game this is a bit inconvenient. Does anyone have a solution?
I'd be happy enough if I could make the arrow-keys cause an Event pointing at the W, S, A, D keys since they are often used too for movement.

One more thing, I get which key caused the Event by calling getEventCharacter() and it works fine for pressing keys but I just get a blank instead of a key when I release the key. I need a reliable way of telling when a certain key which is held down is released. Any ideas?
28  Game Development / Newbie & Debugging Questions / Re: Problem with Writing text to a File on: 2014-04-09 11:43:03
Thank you for the help everyone!
I managed to solve the problem by simply reading/writing the encrypted text as pure short values.
29  Game Development / Newbie & Debugging Questions / Re: Listening to Keyboard while using OpenGL on: 2014-04-09 11:34:40
@tom_mai78101
Thank you for a lot of information. I'm going to start reading it straight away  Grin
One quick questiong though (to avoid doing an embarrasing mistake like I did recently), does the KyeBoard have to be controlled by the same Thread as the one which handles OpenGL or can I just create it and let another Thread handle it? I want to have one Thread for the graphics and one for everything else and if it's possible to do this it would simplify things.

Thank you very much for the help!
30  Game Development / Newbie & Debugging Questions / Listening to Keyboard while using OpenGL on: 2014-04-09 07:24:35
I have just started using OpenGL and I need to be able to listen to the keyboard.
Earlier I used to make a boolean[] (of length 8192) and add a KeyListener. Then I'd just set it so that the information would get put into the array. Like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
buttonsPressed = new boolean[8192];
      frame.addKeyListener(new KeyListener() {
         
         @Override
         public void keyTyped(KeyEvent e) {/*Not used*/}
         
         @Override
         public void keyPressed(KeyEvent e) {
            buttonsPressed[e.getKeyCode()] = true;
         }
         
         @Override
         public void keyReleased(KeyEvent e) {
            buttonsPressed[e.getKeyCode()] = false;
         }
      });


Now I wonder, how am I supposed to do the same thing with OpenGL?
I have no idea how to do this, can you just go "Display.addaddKeyListener(new KeyListener()..." maybe? (I find that a bit unlikely)
Pages: [1] 2
 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (15 views)
2014-09-18 18:14:18

Dwinin (33 views)
2014-09-12 00:08:26

Norakomi (58 views)
2014-09-10 04:57:51

TehJavaDev (81 views)
2014-09-09 21:39:09

Tekkerue (40 views)
2014-09-08 17:24:56

mitcheeb (63 views)
2014-09-07 21:06:29

BurntPizza (46 views)
2014-09-06 16:13:42

Longarmx (33 views)
2014-09-06 16:12:14

Longarmx (38 views)
2014-09-06 16:11:22

Longarmx (36 views)
2014-09-06 16:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

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

HotSpot Options
by dleskov
2014-07-08 01: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!