Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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: [LWJGL] How to properly load images and use them in a JAR on: 2014-05-11 00:07:27
Here are some Image Utilities I use all the time: http://pastebin.com/JBQ8B8Y0

To load a image call:
1  
wood = ImageUtils.loadBufferedImage("res/Baddy.png");


This will work for all Systems, for eg, Windows, Linux, Mac.
2  Java Game APIs & Engines / Java 2D / Re: ISOMetric Sort Order Issue on: 2014-05-10 04:47:29
Resolved by comparing the X then the Z as seen below like mentioned above. (Ignoring Y altogether)
Well this at least seems to fix the height issue, I will have to test width when I make a object for one.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
@Override
   public int compare(GameObject o1, GameObject o2) {
      if(o1.getX() < o2.getX())
         return 1;
      else if(o1.getX() > o2.getX())
         return -1;
      else
         return 0;
   }

   @Override
   public int compare(GameObject o1, GameObject o2) {
      if(o1.getZ() < o2.getZ())
         return -1;
      else if(o1.getZ() > o2.getZ())
         return 1;
      else
         return 0;
   }


And then in my update method I just call them in order.

1  
2  
         Collections.sort(gameObjects, goX);
         Collections.sort(gameObjects, goZ);


Picture one:


Picture two:



Thanks Guys Cheesy
3  Java Game APIs & Engines / Java 2D / Re: ISOMetric Sort Order Issue on: 2014-05-10 01:53:57
Depends a bit on how you are storing/drawing your objects. If you only have a 2d array, e.g., you can simply draw them in order from lowest to highest like Riven suggests. But glancing at your comparator, simply sorting by depth (x+y+z) should work:

1  
2  
3  
4  
5  
6  
   @Override
   public int compare(GameObject e1, GameObject e2) {
      int a = e1.getX() + e1.getY() + e1.getZ();
      int b = e2.getX() + e2.getY() + e2.getZ();
      return (a < b) ? -1 : 1;
   }


The above method yields the same results.
I haven't been able to work out a good way of sorting by rows and such yet.

The Objects are stored in an ArrayList and then to render I use a for loop as seen below.
1  
2  
for(GameObject go : gameObjects)
            go.render(g);
4  Java Game APIs & Engines / Java 2D / Re: ISOMetric Sort Order Issue on: 2014-05-09 11:13:30
1. first sort by X axis
2. then sort (whatever is on the same row) by Z axis
3. then sort (whatever is on the same tile) by Y axis (height)

This means that for every tile you visit, you draw the items from lowest to highest.


Thanks, ill give this a go.
5  Java Game APIs & Engines / Java 2D / SOLVED - ISOMetric Sort Order Issue on: 2014-05-09 09:13:27
Hi there.

I am trying to sort objects on an ISOMetric map to get the correct drawing order. I have tried using the below example which works perfect when all the objects are the same Height and Width but as soon as the Height or Width changes then this method is no longer accurate as seen in the pictures.

I have tried searching the forums and internet for how others have overcome this issue and the answers seem to be use OpenGL etc... I am sure there has to be another way to accomplish this with some math... If anyone knows of a way to correct this issue or can point me in the right direction it would be appreciated.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
package com.deadendertainment.chat.objects;

import java.util.Comparator;

import com.deadendertainment.chat.ChatGame;
import com.deadendertainment.chat.characters.Player;

/**
 *
 * @author Fsig
 *
 */

public class GameObjectComparator implements Comparator<GameObject>{

   @Override
   public int compare(GameObject e1, GameObject e2) {
      return (int) ((e1.getX() - e2.getX()) - (e1.getZ() - e2.getZ()) - (e1.getY() - e2.getY()));
   }

}


Example picture one:


Example picture two:
6  Game Development / Game Mechanics / Re: Creating a command line similar to MS-DOS. on: 2013-06-25 23:48:37
Hello all, I'm in the middle of working on a game, 'Pixel-Space: The Next Adventure' as you know it, and I'm attempting to implement computers into the game. Does anyone have any good advice or shared code that might be helpful?

I attempted it a while back and was stunned at how many different things you would need to think about. All help is appreciated.
Basically, I'm referring to the blank command line that you can perform commands on. Think of it like trying to create a console from scratch, mainly using java.awt.graphics.

Thanks in advance.  Smiley

If it's just a simple command line, write down a list of commands you need.
Then when the user enters anything into the command prompt check the entered string against a array for stored commands, if the command is valid proceed to doing what ever it is the command is supposed to do.

Is there anything in particular that you need help with?
7  Game Development / Game Play & Game Design / Re: How'd you implement an action not being repeated when the button is held down? on: 2013-06-25 23:41:12
I stored the pressed key's in a array.
Then I created a method to release the key from the array.

So there is a simple boolean check to see if a key is down (in the array).

So check if your key is down, if it is do the action, after the action, release the key.
8  Game Development / Newbie & Debugging Questions / Re: Saving Inventory Items on: 2013-05-10 04:42:44
I'm using just pure java Cheesy, I managed to assign an individual id to each item now I am just trying to figure out how to function like I need it to :/

So now you could have your items store a image location or you could make your images have the same ID as your items.

If you item stores a image location you would look up your item by it's ID and get the image location.
If you save the image with the same ID then you just load the image using the ID as the file name.

Here is a example of loading a image with the ID as the file name.

ImageLoad.java
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  
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import javax.imageio.ImageIO;


public class ImageLoad {
   
   /**
    * Read the item file and load the item image.
    */

   public ImageLoad(){
      //File name (Location is assuming the file is in the same folder)
      String itemFile = "./myitem.txt";
      String imageFileName = "";
     
      //Get the file
      BufferedReader input = new BufferedReader(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(itemFile)));
      String line;
     
      //Read the file line by line.
      try{
         while((line = input.readLine()) != null){
            imageFileName = line.split(":")[1].trim();
         }
      }catch(Exception e){
         e.printStackTrace();
      }
     
      //Echo the image filename
      System.out.println(imageFileName);
     
      //Load the image
      BufferedImage myItemImage = loadImage("./" + imageFileName + ".png");
     
      //Echo the image
      System.out.println(myItemImage);
   }
   
   /**
    * Method to load a image.
    *
    * @param ref
    * @return BufferedImage
    */

   public BufferedImage loadImage(String ref){
      BufferedImage bimg = null;
     
      try{
         bimg = ImageIO.read(this.getClass().getClassLoader().getResource(ref));
      }catch(Exception e){
         e.printStackTrace();
      }
     
      return bimg;
   }
   
   /**
    * Start.
    *
    * @param args
    */

   public static void main(String args[]){
      new ImageLoad();
   }

}


myItem.txt
1  
Image: 1


1.png
This is just a image made in paint 5x5 pixels with a black background.

Output:
1  
2  
1
BufferedImage@7b19f779: type = 6 ColorModel: #pixelBits = 32 numComponents = 4 color space = java.awt.color.ICC_ColorSpace@65c66812 transparency = 3 has alpha = true isAlphaPre = false ByteInterleavedRaster: width = 5 height = 5 #numDataElements 4 dataOff[0] = 3
9  Game Development / Newbie & Debugging Questions / Re: Saving Inventory Items on: 2013-05-10 01:39:22
Why are you trying to save the image to a file?

Just save a value which tells you what image to load.

If you must save the image to a file then first convert it to Base64 and get the string. Save this to a file. When loading, convert the Base64 back to bytes then you can use a input stream from you byte array to load a image.

10  Game Development / Newbie & Debugging Questions / Re: Finding nearest objects on: 2013-05-09 12:20:29
100,000,000 times. And that 60 times per second

Ah that makes sense.

Thank you.
11  Game Development / Newbie & Debugging Questions / Re: Finding nearest objects on: 2013-05-09 06:45:20
Distance uses
Math.sqrt()
which is slow.

Hmm... It really doesn't seem slow at all...

Here is a little test I wrote up: http://pastebin.com/Yf5e3vst

And here are the results:
1  
2  
3  
Average time TOTAL (10 loops of 100 loops): 0.016ms to find the closest point out of 100 points.
Average time TOTAL (10 loops of 100 loops): 0.124ms to find the closest point out of 10000 points.
Average time TOTAL (10 loops of 100 loops): 12.838999999999999ms to find the closest point out of 1000000 points.


Either I am testing this all wrong... or it really isn't a problem using a simple method?
12  Game Development / Newbie & Debugging Questions / Re: Finding nearest objects on: 2013-05-09 05:52:30
Would the performance of this be much better then something simple like this...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
   
public static Point getClosest(Point start, ArrayList<Point> points) {
      closest = null;
      nearest = 9999;

      for(Point p : points){
         if(p != null && p.distance(start) < nearest){
            nearest = (int) p.distance(start);
            closest = p;
         }
      }
     
      return closest;
   }
13  Game Development / Newbie & Debugging Questions / Re: Problems with vertical tearing using Bufferstrategy FSEM on: 2013-05-09 05:42:49
Hi there.

I also encounted this error when I first started playing around with the Bufferstrategy.

For me the problem was not with the buffer or rendering methods at all but with how I handled my input.

For example I had a KeyListener on my canvas which I would use to update map movement etc...
To fix it, in the KeyListener I just set a boolean value of up,down,left,right equals true then in my update method I would check if up,down,left,right equals true and if it did I would process my movement.

By doing this you update all your map,units etc before rendering so there is no tearing.
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.

Longarmx (45 views)
2014-10-17 03:59:02

Norakomi (36 views)
2014-10-16 15:22:06

Norakomi (27 views)
2014-10-16 15:20:20

lcass (31 views)
2014-10-15 16:18:58

TehJavaDev (61 views)
2014-10-14 00:39:48

TehJavaDev (61 views)
2014-10-14 00:35:47

TehJavaDev (51 views)
2014-10-14 00:32:37

BurntPizza (67 views)
2014-10-11 23:24:42

BurntPizza (39 views)
2014-10-11 23:10:45

BurntPizza (81 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!