Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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 3 ... 6
1  Game Development / Newbie & Debugging Questions / Re: BufferedImage to Texture [one more tiny question] on: 2014-06-26 00:24:43
Thanks

I've actually read a lot of tutorials
I would load in Textures straight from files, like you have, but I already have so much code behind my dynamically created Sprite Batches (made as a giant BufferedImage) that I would much rather just convert that into a Texture. It also makes my life easier because I don't have to code in anywhere where each sprite is located on the batch
2  Game Development / Newbie & Debugging Questions / Re: BufferedImage to Texture [one more tiny question] on: 2014-06-26 00:01:40
When the guy says,

Quote
My textures are already allocated (as RGBA8) by this point.

How does one go about actually doing that?

1  
Texture texture = ???

Thanks
3  Game Development / Newbie & Debugging Questions / Re: BufferedImage to Texture on: 2014-06-24 17:47:53
Ah, that's the code I was wondering about, changing a buffer into a texture.

Thank you!
4  Game Development / Newbie & Debugging Questions / BufferedImage to Texture on: 2014-06-24 16:58:09
Ok... I'm going through the painful process of moving a game that is well under development from Java2D into LWJGL

I've already made a system that dynamically makes a huge sprite sheet and remembers where all the sprites are, so the whole binding Texture should be ready to go.

Now here's the one method I need to implement before I can proceed (and it'll only be called once or maybe a few times per game)

I need to make a BufferedImage into a Texture object

I don't care if it's really ugly or really "slow", because it's a very rare method

I'm having a hard time figuring out how to accomplish this. Does anyone know?

Thanks
5  Game Development / Newbie & Debugging Questions / Just how bad is it to keep binding? on: 2014-06-23 18:28:07
I'm now about to embark on the painful process of converting a project I have made in Java2D to LWJGL. Before I start, I have one question.

How "bad" is it to keep binding new textures?

People keep saying how much faster it is to have multiple sprites in a single texture and draw different parts of that texture. But if I'm just making a 2D tile-based game, how necessary is that, really?

Will I run into problems with 60fps when I'm binding 100 textures each frame? 1,000? 10,000?

Is keeping everything in one texture really THAT worth it?
6  Game Development / Newbie & Debugging Questions / How slow is drawing things on a Graphics2D object? on: 2014-06-23 00:53:45
Whenever my game goes fullscreen the framerate drops to 30 from 60. I'm barely drawing anything. This really shouldn't be happening, it's just a very simple 2D game. Is this just a fault of the system I'm using? Is there anyway to make it faster? I can provide any specific information you might need

Thanks
7  Game Development / Newbie & Debugging Questions / Re: Scanner works in "spurts" when piping on: 2014-02-09 23:39:54
Doesn't that seem unnecessarily complicated? My program should also be reading the data continuously, at the same pace that data is being written to the command line. Is there a way to use the buffer without writing it to a file?
8  Game Development / Newbie & Debugging Questions / Scanner works in "spurts" when piping on: 2014-02-09 22:14:45
I'm making a project where I'm taking in data from another program via the command line

If my JAR is called "project.jar", and the data-maker program is called "program" I am taking in data like this:

1  
program | java -jar project.jar


When I did this, I noticed that there was a significant amount of lag in my program. Not in the framerate at all, but rather in the rate at which the lines generated by "program" were fed into "project.jar" at an inconsistent rate. To see if this was a problem with "project.jar", I made a new JAR which is literally this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
import java.util.Scanner;

public class Printer {
   
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      while(true){
         System.out.println(sc.nextLine());
      }
   }

}


Now, "program" generates data very quickly, maybe 10 lines a second. But when I set up
1  
program | java -jar printer.jar


then THIS prints out data in the same spurts! There would be 3 or 4 seconds before a massive chunk of lines would be printed out. Why should this happen? If I pipe "program" into "printer", I should see it printing everything out continuously at the same rate "program" does.

Is this a problem with piping, or with the Scanner class, or what? How can I fix this so Scanner reads things more continuously?

Thanks
9  Game Development / Newbie & Debugging Questions / Re: "Unclosed character class near index 0" ? on: 2014-01-19 21:01:49
str.split("\\]")


That's very weird. I did not know about that. Now it works though!
10  Game Development / Newbie & Debugging Questions / Re: "Unclosed character class near index 0" ? on: 2014-01-19 20:55:31
I don't know anything about regex, I'm not gonna lie. But I was under the impression that "split" just returned an array of strings, cutting up your string using the argument as a divider

for example,

"A,B,C,D,E".split(",") = {"A", "B", "C", "D", "E"}

And that is actually true

If this ISN'T always the case, then how can I get the behavior I'm looking for?
11  Game Development / Newbie & Debugging Questions / "Unclosed character class near index 0" ? [solved] on: 2014-01-19 20:46:40
Long story short, I'm making a class to read text files in a specific way. I'm storing a lot of information about my game (including enemy stats) in text files that I read in and parse appropriately. I am not writing that class, and getting a very biazzare error.

My centralized "parsing" involves taking a string and making two String[] arrays, one that contains everything in square brackets, and one that contains everything outside of square brackets.

For example, this string
1  
2  
3  
4  
5  
6  
7  
8  
NAME: [NAME]
FILE: [FILE]
TYPE: [TYPE1] [TYPE2]
COLOR: [COLOR]
HP: [HP]
PWR: [PWR]
DEF: [DEF]
SPD: [SPD]


Should be parsed, via the method "splitInBrackets" into:
1  
[NAME, FILE, TYPE1, TYPE2, COLOR, HP, PWR, DEF, SD]


Now, when I pass that exact string into my method, I get this error:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
Caused by: java.util.regex.PatternSyntaxException: Unclosed character class near index 0
[
^
   at java.util.regex.Pattern.error(Unknown Source)
   at java.util.regex.Pattern.clazz(Unknown Source)
   at java.util.regex.Pattern.sequence(Unknown Source)
   at java.util.regex.Pattern.expr(Unknown Source)
   at java.util.regex.Pattern.compile(Unknown Source)
   at java.util.regex.Pattern.<init>(Unknown Source)
   at java.util.regex.Pattern.compile(Unknown Source)
   at java.lang.String.split(Unknown Source)
   at java.lang.String.split(Unknown Source)


at the line that says "String[] comp = ref.split("[");"

Why is this happening? (Method code below)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
private String[] splitInBrackets(String ref){
      System.out.println(ref);
      String[] comp = ref.split("[");
      //split
     //NAME: [NAME] AGE: [AGE]
     //into
     //|NAME: |NAME] AGE: |AGE]
     //then for each component splits it further to get out the parts in the [ ]
     
      //will throw out of bounds exception if weird stuff isn't formatted with the brackets
     for(int i = 1; i < comp.length; i++){
         String[] dcomp = comp[i].split("]");
         comp[i] = dcomp[0];
      }
     
      return comp;
   }
12  Game Development / Newbie & Debugging Questions / Re: Limits of drawing BufferedImages? on: 2014-01-10 01:25:50
Also make sure you are not using getRGB, setRGB, getDataBuffer or anything like that, those calls will cause Java2D to unaccelerate the image.

I use those calls to load some BufferedImage instances initially, but I only do these things once at the start and not every frame. I've made my game so all images are in on a grayscale and "colorized" by taking the RGB array using getRGB from image files, doing some math on all the pixels, and then making a new BufferedImage using setRGB
13  Game Development / Newbie & Debugging Questions / Limits of drawing BufferedImages? on: 2014-01-09 17:53:49
I am making a game with pure java, drawing BufferedImage objects to a Graphics2D object.

My game has a simple rendering system, namely it just draws a bunch of tiles.

However, I have found that when I draw too many images onto the screen in one frame (name 1/60th of a second), this number being around 1000, my fps drops to around 30.

Is there a better way to do this? How can I draw images faster?
14  Game Development / Newbie & Debugging Questions / Re: Brighten RGB color? on: 2014-01-03 08:10:29
That first article was very good! Using it, I made my own class that can brighten colors in the way I wanted.

I will post it here in case someone else in the future is trying to do the same thing.

I tested it and it works Smiley

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  
import java.awt.Color;

public class ColorOperator {
   
   //colorInt should be a standard rgb hex value, like 0xffffff
  //light  should be a number from 0 to 255, 0 being black, 255 being white
  //returns a hex rgb int at the appropriate brightness level
  public static int setColorBrightness(int colorInt, int light){
      int r = ( colorInt >> 16 ) & 0xff;
      int g = ( colorInt >> 8 ) & 0xff;
      int b = ( colorInt ) & 0xff;

      float[] hsb = Color.RGBtoHSB(r, g, b, null);
      float[] hsl = HSBtoHSL(hsb);
      hsl[2] = light / 255f;
      hsb = HSLtoHSB(hsl);
           
      return Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]) & 0xffffff;
   }
   
   public static float[] HSBtoHSL(float[] hsb){
      float[] hsl = new float[3];
     
      float l = (2 - hsb[1]) * hsb[2] / 2;
      float d = (l < .5f ? l * 2 : 2f - l * 2);
     
      hsl[0] = hsb[0];
      hsl[1] = d == 0 ? 0 : hsb[1] * hsb[2] / d;
      hsl[2] = l;
     
      return hsl;
   }
   
   public static float[] HSLtoHSB(float[] hsl){
      float[] hsb = new float[3];
     
      float b = hsl[2] + hsl[1] * (hsl[2] < .5f ? hsl[2] * 2 : 2 - hsl[2] * 2) / 2;
     
      hsb[0] = hsl[0];
      hsb[1] = b == 0 ? 0 : 2 * (1 - hsl[2] / b);
      hsb[2] = b;
     
      return hsb;
   }

}
15  Game Development / Newbie & Debugging Questions / Re: Brighten RGB color? on: 2014-01-02 06:06:56
Ahhh, I thought HSB was the same as HSL, but it is actually the same as HSV. So that makes more sense. If anyone knows of a way to convert from HSB to HSL, I'd be appreciate it.
16  Game Development / Newbie & Debugging Questions / Brighten RGB color? [solved] on: 2014-01-02 04:12:03
I thought I'd be able to find an answer to this, but it's turned out to be harder than I thought.

In MS paint, there's a color editor tool that lets you brighten colors


My question is, what is the math behind that color brightening tool, rgb wise?

I thought that if I took a color, and converted the brightness in the "HSB" color model presented by the Color class, I would get an identical effect. However, this isn't quite what I was looking for. For example, it's impossible for me to brighten purple all the way up to white. It merely becomes a very bright purple. Using the Color class "brighten" and "darken" methods produce the same result.

So, simply put, how, numerically, can I implement a method that brightens or darkens a color by an amount that produces an effect identical to that in the picture?

Thanks
17  Game Development / Newbie & Debugging Questions / Re: JFrame dimensions? on: 2013-12-31 03:40:12
So how could I get the width and height using the aforementioned frame.getWidth() and the "getInset()" method, because the only variables I see from the Inset are top, bottom, right, and left, and I don't quite see how to use that information. I don't quite understand what to add and subtract.

Thanks
18  Game Development / Newbie & Debugging Questions / JFrame dimensions? on: 2013-12-31 02:46:30
I want my next game to have a re sizable window (no external libraries used)

How do I get the size of the interior of the JFrame?
What I mean is, I can get the total width/height of the JFrame "frame" via "frame.getWidth()"

The problem is that I set the size of the frame to be 640 x 480, but when I get the dimensions via the method above, I get 646 x 509.

I can only imagine that the numbers get bigger because of the size of the border of the window.

But I don't want those dimensions, I want the dimensions of what I'm actually drawing on.

I know I could just subtract 6 and 29, but that won't work for every OS.

So how can I get the dimensions I'm looking for?

Thanks.
19  Game Development / Newbie & Debugging Questions / Piping into a JAR [solved] on: 2013-12-12 11:27:15
I have jar called thing.jar
It continuously receives output from the console
So when I run

1  
java -jar thing.jar

and then start typing away at the keyboard, everything I type is received by the scanner in thing.jar

Now I have a little class file, FakeInput, such that when I run

1  
java FakeInput

It just creates a whole lotta random output, printing it onto the console (with a 10 millisecond delay between each print) until I press ctrl-c and tell it to stop.

I want to pipe the OUTPUT from FakeInput into the INPUT of thing.jar

So why doesn't these lines work?

1  
2  
java FakeInput | java -jar thing.jar
java -jar thing.jar < java FakeInput

Some weird errors happen instead, the gui window for thing.jar freezes, but shouldn't there be a way to run them at the same time?

How can I do what I want?
Thank you.

EDIT: I SOLVED THE PROBLEM. For anyone reading the thread in the future,
1  
java FakeInput | java -jar thing.jar

Totally works. The only problem is that a 10 millisecond delay was much to short. I changed it to 100 milliseconds and it works.
Thanks.
20  Game Development / Newbie & Debugging Questions / Re: Compiling and running a LWJGL Project on: 2013-12-12 11:24:00
You are a saint! Thank you so much!

For those of you who read this later, do what he said and put your natives in the folder "Windows" (for example) which is in the folder "nat" which is in the same folder as your JAR
21  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-12-12 10:31:35
Ok, It's asking me for parameters, but I don't understand where exactly to put them
Should I run it like this (if my jar is named Game.jar and I had eclipse export the libraries into the folder Game_lib

java -jar FatJar -lib Game_lib -main package.Main -output FatGame.jar

Where do I even specify to use Game.jar?
22  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-12-12 04:01:56
Ok cool, but how do I use it? What parameters does it take?
23  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-12-12 03:03:46
The first time I ran it there was an error in the console (if I remember correctly) but I ran it again, and while there was no error, no window opened either.
24  Game Development / Newbie & Debugging Questions / Compiling and running a LWJGL Project [solved] on: 2013-12-12 02:24:34
Very simply, how can this be done?
I do not mind if I have to write a complicated batch file.
I have been trying to do this for a while and it is very confusing. For example, how can I edit a manifest file in eclipse? What exactly do I have to do?

I can't use JarSplice in it's current state because it won't let me take input from the command line.

I am using 3 Jars in my library: lwjgl_util.jar, lwjgl.jar, slick.jar

How exactly can I run my project outside of my IDE in cmd?

Thanks!
25  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-12-12 02:20:07
I get an error when I run it.
26  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 14:05:45
The problem here has nothing to do with your code at all. It is JarSplice's fault. When running the JAR that is spit out by JarSplice, you are actually running its launcher, which, now that I look at the code, does not forward its stdin stream to your program. I'll talk to kappa about fixing this bug.

Ah yes! Why didn't I think of that? Previously, before I moved my project to LWJGL, I had no reason to use Jarsplice, so I didn't. I didn't even imagine that Jarsplice would be the source of this problem. Thanks for pointing this out, I'll now work on finding a way to launch my project without Jarsplice...
27  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 03:36:50
Ok, let me explain how this project is used.

That's exactly right, this project is accepting lines from the scanner on an infinite loop, updating things in the program according to structured strings put into the console.

The actual use of this is to read data from a microsoft kinect. Once again, this is only a pet project, so I didn't want to get bogged down in confusing libraries.

I found a program online that outputs data from the kinect into lines on the command prompt. So for example, if two people are walking around a room, the output can look like this, where a new line is written every fraction of a second or so:

1  
2  
3  
4  
5  
6  
7  
8  
user 1: head at (444, 444, 444)
user 2: head at (1001, 1000, 1000)
user 1: head at (444, 445, 444)
user 2: head at (1002, 1000, 1000)
user 1: head at (444, 446, 444)
user 2: head at (1003, 1000, 1000)
user 1: head at (444, 447, 444)
user 2: head at (1004, 1000, 1000)


By piping this data into my Jar in the command line, I can very easily pipe all this data into my program.
For example, I can do this like this in the command line:
1  
NISimpleSkeleton.exe | java -jar project.jar

where NISimpleSkeleton.exe is the program that outputs the data from the kinect into the command line. My JAR reads this data in real time and updates the program accordingly.

This method of organization works very well. The only problems came from when I changed the "engine" of this project to the LWJGL, at which point it stopped working for the simple reason that it stopped being able to accept the data from the command line.

That is how I am using the scanner, I hope that brings light to the issue.
28  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 03:16:45
I don't quite see how that will help.
Here is my class that reads in the input, for reference. It runs in it's own Thread parallel to two other threads in my program:

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  
import java.util.Scanner;

public class Reader implements Runnable {

   Scanner sc = new Scanner(System.in);
   
   public Reader(){}
   
   public void run() {
      while(AudioRunner.keepGoing){
         String input = sc.nextLine();

         AudioRunner.pause();
         while(!AudioRunner.hasStopped){
            sleep(10);
         }

         Person.updatePeople(input);
         
         AudioRunner.resume();
      }
   }
   
   private void sleep(int time){
      try {
         Thread.sleep(time);
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }

}


The "updatePeople()" method does many operations on the received String. Here is what that method looks like:

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  
public static void updatePeople(String input){
      Feed.nextLine(input);
     
      if(input.length() < 10 || !input.substring(0, 5).equals("user "))
         return;

      input = input.replace("user ", "");
      char numChar = input.charAt(0);
      int numPerson = Integer.parseInt(numChar+"");
     
      while(numPerson > numberOfPeople)
         new Person();

      people.get(numPerson-1).updatePerson(input);
   }

public void updatePerson(String input){
      if(input.charAt(0) != '('){
         updatePerson(input.substring(1));
         return;
      }
     
      input = input.substring(1,input.length()-1);
      input = input.replaceAll(" ", "");
     
      String[] coordsString = input.split(",");
      double[] coords = new double[3];
      for(int i = 0; i < 3; i++)
         coords[i] = Double.parseDouble(coordsString[i]);
     
      //left is more negative x
     setLocation(coords[0], coords[1], coords[2]);
   }


This code isn't meant to be understandable for anyone but me, really, because this is a pet project. The point is that I'm doing many operations on many received strings, and I am splitting them using ',' for the purposes of parsing strings into useful data. This works fine when I'm not using the LWJGL
29  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 02:52:59
I am 99% sure this is a problem relating to input and not something else. My previous project that takes in console input in and identical way (through the Scanner) acts as expected. The program in question (along with that OpenAL demo I linked to) will not accept console input.

The thing is that when I type things into the console I AM using new lines. If I type in multiple commands (separated by new lines) then each "command" is parroted back out to me separately when the program ends.

So how can I configure everything so things are accepted into the scanner with each new line?

Thanks so much!
30  Game Development / Newbie & Debugging Questions / Re: Does LWJGL affect input from the command line? [unsolved] on: 2013-11-28 01:19:41
Using JarSplice I have been able to make everything work as I would hope. As I need to put input into my program using the command prompt, I don't need to be able to click the icon to make it run, but rather use the command "java -jar program.jar"

So if I were to transfer my project to NetBeans (which could take a while) what would you suggest I look into so that the Jar will properly take in things from the console? I don't see much written about this subject currently and I'm not sure how to proceed.

Thanks
Pages: [1] 2 3 ... 6
 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

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

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

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

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

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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!