Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
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: Converting Java desktop game to applet? on: 2013-11-12 00:33:22
Well yea, you have to make a new class, Apple, for example.

Since your Game class extends the Canvas class - you can simply use the JApplets "add()" method (which basically works exactly like JFrame add() method) to add your game (which is a Canvas).
Didn't catch that, my bad!
I typed this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
import javax.swing.JApplet;

public class GGame extends JApplet {

   private static final long serialVersionUID = 1L;

   public static void main(String[] args) {
      new GGame().init();
   }

   public void init() {
      Game g = new Game();
      this.add(g);
      Game.init();
   }

}

(Game.init() is the same code in the OP that creates the JFrame and whatnot.)

I don't have the time to test it online but when I compiled it Eclipse suggested running it as an application and rendering, input & everything worked perfectly.
Thank you for your help!
2  Game Development / Newbie & Debugging Questions / Re: Converting Java desktop game to applet? on: 2013-11-12 00:18:50
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public class Apple extends JApplet {
   public void start() {
      Game g = new Game();
      // add listeners etc
     
      this.add( g );
      // request focus etc, possibly set size

      g.start();
   }
 
   // play(), stop() etc
}


Should pretty much do the trick I think.
1  
public class Game extends Canvas extends JApplet implements Runnable {

Syntax error on token "extends", . expected

I don't think you can extend a class twice, so any idea how I could work around this?
3  Game Development / Newbie & Debugging Questions / Converting Java desktop game to applet? on: 2013-11-12 00:11:10
I have a desktop Java game I'd like to run on a browser. Some people say I need to use Applet or JApplet for this but I haven't caught a straight answer.

I'm using JFrame, BufferStrategy & Thread if that's relevant in any way and here's the code of interest:
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  
public class Game extends Canvas implements Runnable {
   
   public static void main(String[] args) {
     
      Game g = new Game();
      g.addKeyListener(new Input());
      g.setFocusable(true);
     
      JFrame f = new JFrame("OMG A TITLE");
      f.add(g);
      f.pack();
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setSize(W, H);
      f.setResizable(false);
      f.setLocationRelativeTo(null);
      f.setIconImage(icon);
      f.setVisible(true);
     
      g.start();
     
   }
   
   public void start() {
      new Thread(this).start();
   }
   
   public void run() {
      // updatin' 'n' stuff..
  }
   
   public void render() {
     
      BufferStrategy bs = getBufferStrategy();
      if (bs == null) {
         createBufferStrategy(2);
         return;
      }
      g = bs.getDrawGraphics();
     
      Room.render(); // rendering the graphics with the use of g
     
      g.dispose();
      bs.show();
     
   }
   
}

(Let me know if the code is not so relevant.)

I also have a class for handling key inputs by implementing KeyListener.

The question, what should I change in the code in order for it to be runnable in a browser?
4  Game Development / Newbie & Debugging Questions / Re: Image excluded when exporting into a jar? on: 2013-11-09 14:41:57
Yes for sure.
Thanks a bunch! Going back to actually making progress on my game!
5  Game Development / Newbie & Debugging Questions / Re: Image excluded when exporting into a jar? on: 2013-11-09 14:40:18
What use is there in using my original method of grabbing images since it doesn't work after exporting?

Your former method doesn't work when inside JAR because
File
isn't supported inside JAR files. It can be useful if the resources were placed outside the JAR file.
So I can export a jar file and have my folder of images in the same directory, and the jar could grab those files?
6  Game Development / Newbie & Debugging Questions / Re: Image excluded when exporting into a jar? on: 2013-11-09 14:29:08
Your problem is your class is in the source folder already, so you don't need to reference it when loading the image. Try removing the "src/" completely when loading the image.
I edited my code like your suggestion yesterday without trying it out because I was tired and thought it was going to do nothing.
I just tried it out and everything works perfectly! Thanks for the help everyone!

Edit: Follow-up question out of curiosity: What use is there in using my original method of grabbing images since it doesn't work after exporting?
7  Game Development / Newbie & Debugging Questions / Re: Image excluded when exporting into a jar? on: 2013-11-09 02:23:08
Seems way too simple and trivial but did you try removing the "/" before "src"?
1  
image[i] = ImageIO.read(Foo.class.getClassLoader().getResourceAsStream("/src/" + i + ".png"));

to
1  
image[i] = ImageIO.read(Foo.class.getClassLoader().getResourceAsStream("src/" + i + ".png"));

I already tried that with no luck  Undecided
8  Game Development / Newbie & Debugging Questions / Re: Image excluded when exporting into a jar? on: 2013-11-09 02:00:41
Replace your code with this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
public static void loadImages() {
      for (byte i = 0; i < 1; i++) {
         try {
            image[i] = ImageIO.read(getClass().getClassLoader().getResourceAsStream("/src/" + i + ".png"));
         } catch (IOException e) {
            e.printStackTrace();
         }
      }
   }


Why your code doesnt work: You cant access a file inside a JAR file with File. You need the input stream.

I replaced the code and got an error message regarding static context. After editing the function to non-static in your version of the code I got this error upon compiling:
1  
2  
3  
4  
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
   at javax.imageio.ImageIO.read(Unknown Source)
   at Background.loadImages(Background.java:16)
   at Game.main(Game.java:45)

Background.java:16:
1  
2  
image[i] = ImageIO.read(getClass().getClassLoader()
                  .getResourceAsStream(i + ".png"));

Game.java:45:
1  
new Background().loadImages();


The last piece of code is executed when launching the project. I normally would use the entire class Background in a static context and I suspect that might be the problem.
Does anybody have any idea?
9  Game Development / Newbie & Debugging Questions / Image excluded when exporting into a jar? on: 2013-11-09 01:26:03
My java project looks like this:
FirstGame
   src
      (default package)
      0.png

(The code is stored in default package.)

I load my images:
1  
2  
3  
4  
5  
6  
7  
8  
9  
public static void loadImages() {
      for (byte i = 0; i < 1; i++) {
         try {
            image[i] = ImageIO.read(new File("src/" + i + ".png"));
         } catch (IOException e) {
            e.printStackTrace();
         }
      }
   }

(No errors are given when compiling and I can display the image in the game.)

When I export the project into a runnable jar file it seems as if the image doesn't exist. I can extract the jar's contents with 7-zip and I can clearly see my image is there however.

So the question is, how do I make sure the image is included and in the right place when I export it?
10  Game Development / Newbie & Debugging Questions / Re: Looping through ArrayList using enums? on: 2013-10-07 15:05:39
Your example code is not complete, wouldn't compile. So I can only throw some random thought at you.
When you create one enum you also create only ONE class. Solid, Bad and Bounce in your example are NOT classes they are simple instances of the Block class.

When you want to print a enum instance you can use the .name() method or just rely on the toString method, like:
1  
2  
println("10 " + Block)
//prints "10 Block"

I don't know if I misunderstood but Solid, Bad & Bounce are all classes in my game. The printing is not what I want help with, what I need help with is what I actually wrote in the post.
11  Game Development / Newbie & Debugging Questions / Re: Looping through ArrayList using enums? on: 2013-10-07 15:03:46
Yes, indeed. Also, why make a debug() method? The whole point of debugging is finding the error in some piece of code that your game uses. If it's in the player class, debug it there. If in the game loop, debug it there. Or even better use a debugger.

Also, your enum code isn't valid. Should be a semicolon after Bounce.
My goal is not exactly debugging but the name has nothing to do with it. Plus, according to pretty much all my Google searches, the semicolon is optional when using enums.
12  Game Development / Newbie & Debugging Questions / Looping through ArrayList using enums? on: 2013-10-07 00:46:59
I'm having trouble creating a method which loops through an ArrayList of multiple types of objects.

Here's my failed attempt:
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  
import java.util.ArrayList;

public class DebugObjects {

   public enum Block {
      Solid, Bad, Bounce
   }

   public static void debug(ArrayList<Block> list) {

      for (Block b : list) {

         String n = b.getClass().getName();
         byte i = (byte) Solid.list.indexOf(b);

         if (b.X < 0) {
            System.out.println(n + " " + i + " is outside the left side.");
         }
         if (b.X + b.W > Game.WH) {
            System.out.println(n + " " + i + " is outside the right side.");
         }
         if (b.Y < 0) {
            System.out.println(n + " " + i + " is outside the up side.");
         }
         if (b.Y + b.H > Game.WH) {
            System.out.println(n + " " + i + " is outside the down side.");
         }

      }

   }

}


My goal with this is to be able to call the method like this:
DebugObjects.debug(Solid.list);
This would loop through all Solid objects inside of Solid.list and tell me if any of them exceed the game window.

Thanks in advance!
13  Game Development / Newbie & Debugging Questions / Re: Extending the Color class on: 2013-09-08 02:16:56
It depends on how you're calling it, but I suspect you're trying to override a static method, which won't work.

Don't bother with a custom subtype of Color - that's bad OOP. Instead just move your static blend() function into a utility class somewhere, then call it.
I guess I'll have to do it that annoying way.. Oh well, it's a fun learning experience nonetheless, thanks for the help!
14  Game Development / Newbie & Debugging Questions / Re: Extending the Color class on: 2013-09-08 02:10:28
Are you sure you imported YOUR Color class? Maybe giving it a different name would avoid confusion
All my classes are in the same package so yes. Regarding the name, I'm trying to extend the pre-defined class java.awt.Color, not create another. It would be neat not having to create a whole new class just for one method, that's why I'm trying to extend it.
15  Game Development / Newbie & Debugging Questions / Extending the Color class on: 2013-09-08 01:59:37
Hi, I'm trying to create additional methods for the class java.awt.Color:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public class Color extends java.awt.Color {

   private static final long serialVersionUID = 1L;

   public Color(float r, float g, float b) {
      super(r, g, b);
   }

   public static Color blend(Color c1, Color c2, float f) {
      return new Color(0F,0F,0F,0F);
   }

}


However, when the method blend is called Eclipse says "The method blend(Color, Color, float) is undefined for the type Color".
Do you have any suggestions what may be the problem?
16  Game Development / Newbie & Debugging Questions / Re: Choppy rendering on: 2013-09-03 20:56:43
Bumping because I added a question on top of my gathered answers.
17  Game Development / Newbie & Debugging Questions / Re: Choppy rendering on: 2013-09-01 15:20:04
I think, however I don't know, that you should be setting unprocessed back to 0 every frame as its the delta between two frames. Right now you're subtracting 1 from it and I honestly don't know why you are. Also, triple buffering may be a but much, double should be fine and it'll be less resource intensive. Going from double to triple causes around a 50fps drop on my decent setup.
Edit: any way you could post a video about whats actually happening? I don't really know what you mean by its rendering frames behind other frames.
It seems changing the buffering has solved it, independent of if I'm using nanoseconds or milliseconds!

To answer the delta thing let's say it takes 32 milliseconds to get to the next frame/update (let's imagine we have the world's slowest PC). That means we need to update the game twice in order to not affect the speed of the game. That's why I have a loop which keeps that in order.

And the edit question: I don't know if that would be possible since YouTube only allows for 30 FPS and not 60 which the game is locked at. The best explanation I can give really is this:
You're going to the right. However, every third or second frame or so it looks like the game throws an outdated frame of the game. So if we say we walk to right every now and then a frame would pop up showing the character some pixels behind.

Thanks for the reply!
18  Game Development / Newbie & Debugging Questions / Choppy rendering on: 2013-09-01 04:25:04
I had some problems with choppy rendering where the game would look like it was rendering a frame behind every other frame, mildly straining my eyes.
After some minutes of fooling around I might have solved the problem. What I did differently was using more precision in my game loop (using time in nanoseconds and not milliseconds, exchanging floats for doubles).

My question is, is this all a coincidence and I did not solve the problem and if so, what may be causing the problem?

I'm utilizing JFrame, triple-buffering & basically the loop everyone else is using.
Here is the entire Game class: http://pastebin.com/G9zSb73L

For clarification, the game window is not flickering with black & white images. I just found there are a lot of people having problems with that so I want to make it clear I do not have that problem. Keeping it safe here.


---

Upon launching my game, the canvas in my JFrame is unrendered for one frame. It's basically a grey rectangle flashing before the game starts like every other game. Is there a way of avoiding that?

Here's the code:
http://pastebin.com/yqqZZGbu
19  Game Development / Newbie & Debugging Questions / Re: Raining new color objects - is that a good idea? on: 2013-08-13 04:29:03
Performance shouldn't be an issue, but you might cause epileptic seizures in some of your players...
I'll do my best to prevent that from happening  Wink
20  Game Development / Newbie & Debugging Questions / Re: Raining new color objects - is that a good idea? on: 2013-08-12 22:13:45
Is this going to affect performance much? If so, is there a work-around?
Many thanks!
Honestly, don't worry about the performance of what you throw in your render loop - just the design. Worry about performance when you are doing profiling.
Thank you for that reassuring reply!
21  Game Development / Newbie & Debugging Questions / Raining new color objects - is that a good idea? on: 2013-08-12 22:06:45
Some of you might recognize me from my previous thread (which was a mess of misunderstanding thanks to me). I finally accomplished what I attempted to do and now a question regarding performance troubles me.

60 times each second, my game updates the background's colour:
1  
c = new Color((short)r,(short)g,(short)b);


Is this going to affect performance much? If so, is there a work-around?
Many thanks!
22  Game Development / Newbie & Debugging Questions / Re: Calculate a speed of colour-shifting on: 2013-08-10 20:21:30
Well from that small info you give us, i would assume that you calculate the delta time between the game updates.
I'm not really sure what you're trying to accomplish; but best guess is that you are having trouble shifting smoothly from one value to another.
Check Reply #2 if you want a more proper explanation of my problem.
Are you or are you not trying to animate one color to another? Just use the code I posted, or any other easing/interpolation utility.

Using a "speed" variable and a series of if-else statements is not the correct approach...
See Reply #2 for a much more narrowed down question. I simply want to make my value rise to a specific value over a specific time in seconds. It's all about how to calculate the speed really.
23  Game Development / Newbie & Debugging Questions / Re: Calculate a speed of colour-shifting on: 2013-08-09 23:21:58
Well from that small info you give us, i would assume that you calculate the delta time between the game updates.
I'm not really sure what you're trying to accomplish; but best guess is that you are having trouble shifting smoothly from one value to another.
Check Reply #2 if you want a more proper explanation of my problem.
24  Game Development / Newbie & Debugging Questions / Re: Calculate a speed of colour-shifting on: 2013-08-09 22:26:15
Excuse my messy describing, this is to clear things up:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public static void update() {
      boolean bool = false;
      r += s;
      if (r > cmax) {
         debug1 = System.currentTimeMillis();
         r = cmax;
         s = -s;
         bool = true;
      } else if (r < cmin) {
         debug2 = System.currentTimeMillis();
         r = cmin;
         s = -s;
         bool = true;
      }
      c = new Color((int) r,c.getGreen(),c.getBlue());
      if (bool) System.out.println(debug1-debug2);
   }

s is speed, c is colour, r is amount of red in the original colour
cmax & cmin make the interval r is allowed to be inside.


In the Background class, this method is called 60 times/second.

What I want is the console to print out when r has reached a peak from another.
I'm successful doing so, but I don't know what the speed's value is supposed to be.

Edit: A simpler way of saying this:
I want value r to increase s in the time t.
The update method increases r with s and is called 60 times/second.
What is the value of s?
25  Game Development / Newbie & Debugging Questions / Calculate a speed of colour-shifting on: 2013-08-09 21:45:47
Look at Reply #2 for an easier explanation!

1  
2  
3  
4  
public Background(Color cc, int aa, int tt) {
      c = cc;
      s = ???;
   }

cc is colour, aa is colour deviation and tt is time in seconds. The game updates 60 times/second.

For example, if I passed in Color.PINK, 50, 3 I would basically say this:
My background is in the colour pink by default.
Its colour is going to continuously shift shades.
The time for a shift from the darkest shade to the brightest is going to take 3 seconds.

How would I calculate the speed s with known deviation and time?
26  Game Development / Game Play & Game Design / Re: 2D Platformer - Level Design? on: 2013-08-09 03:20:22
Not to spoil a dying thread but I'd like to share my knowledge:
  • When designing the introduction levels, explain the game's most basic movement techniques (like walking & jumping) through gameplay. Do not throw a splash screen onto the screen telling them what to do.
  • Try not to overwhelm the player with mechanics. Keep it slow and simple in the beginning and gradually increase difficulty and complexity.
  • Make sure the player doesn't forget what you've taught them. Keep reminding them how to do certain things.
  • Have the mindset you're a person completely new to gaming. You don't know what button to press to do anything in any game.
  • Be extremely emotional when playtesting your level. If a particular jump is too wide, making you feel uncomfortable if you can make it across, fix it. This obviously does not apply if you actually want the player feel uncomfortable!
  • Make sure everything valuable in the level is clear and easy to see. You should be able to know with ease what you're able to grab, pass through and collide with.
  • For good practice, play a wide variety of games and criticize them. What is wrong with them, what is good with them? Either write what you learn down or just try to remember what you're learning.
My words of wisdom: Good level design is organic.
Good luck!
27  Game Development / Game Play & Game Design / Re: Emotional motivation in gaming, and Firefly on: 2013-08-09 02:51:11
I'd suggest you play Lone Survivor. It's a horror-adventure, 6-hour single player sort-of-RPG at a fair price on Steam.
Yes it's another zombie apocalypse game, but it's coming from a much less explored angle of feeling helpless and weak.
Excuse me for being off-topic, but I find we partly share interests and this game is one of the best I've come across!
28  Game Development / Game Play & Game Design / Re: Pitch your Game Idea/Concept here! on: 2013-08-09 02:44:41
A nifty idea I've thrown around for some time:
The game is at a fixed, small size. Its character is able to move across the screen just like any game. Upon hitting the edge of the game's window however, you move the entire thing. This is used to scroll the map, discovering that all levels are the size of the monitor.
Similar to a side-scroller, but the view is not centered on the player but rather pushed by the player. I'm not keen to Java so I'll leave this idea to anybody out there!
29  Game Development / Newbie & Debugging Questions / Re: Getting a color in a 0-1 float value on: 2013-08-06 01:19:39
Thanks to both of you, I'm switching to using the 0-255 way of doing it!
30  Game Development / Newbie & Debugging Questions / Re: Getting a color in a 0-1 float value on: 2013-08-06 01:11:20
Which Color class are you using? java.awt.Color ?
That would be correct
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.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (11 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (108 views)
2014-04-08 23:06:04

tom_mai78101 (208 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!