6 Replies - 1080 Views - Last Post: 03 April 2012 - 07:51 AM Rate Topic: -----

#1 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Need some info before i start making Java game

Posted 03 April 2012 - 01:30 AM

Hello guys!

I decided i will try to create a game in Java which i never realy tried. I have some question before i start doing it tho.

1. What do i draw the game to? (Some people told me Canvas is best but i don't know)
2. What do i use in java to type some messages into the game screen? With this question i mean like to test collision for example "Bullet hit the target" message, Like how do i print a message like this to the Canvas or whatever i will use. Since i only know one way and that is displaying an image with the text in it.


Do note that i have never realy created any games in Java before but i realy want to try it :)
Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Need some info before i start making Java game

#2 Mylo   User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

Re: Need some info before i start making Java game

Posted 03 April 2012 - 03:27 AM

1. You can pretty draw in any component, Canvas, Panel, Frame etc. By overriding the paint(Graphics g) method. Swing components (JPanel, JFrame, etc) are already double buffered so it saves you the trouble of setting up a bufferStrategy. I'm not sure if there is a performance hit or whatever though.

2. System.out.println("Bullet hit the target"); for console g.drawString("Bullet hit the target", xPosition, yPosition); for graphics (this goes inside your paint method).

This post has been edited by Mylo: 03 April 2012 - 03:29 AM

Was This Post Helpful? 0
  • +
  • -

#3 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Need some info before i start making Java game

Posted 03 April 2012 - 03:42 AM

View PostMylo, on 03 April 2012 - 10:27 AM, said:

1. You can pretty draw in any component, Canvas, Panel, Frame etc. By overriding the paint(Graphics g) method. Swing components (JPanel, JFrame, etc) are already double buffered so it saves you the trouble of setting up a bufferStrategy. I'm not sure if there is a performance hit or whatever though.

2. System.out.println("Bullet hit the target"); for console g.drawString("Bullet hit the target", xPosition, yPosition); for graphics (this goes inside your paint method).


Thanks for very good answears, Now i need to know which of the Canvas, Panel and Frame will make the application run smoothest. I heard Java applications sometimes do run realy bad so i want to try the best to make it run "quick".

Anyone know which of the three would let the application run best?
Was This Post Helpful? 0
  • +
  • -

#4 Mylo   User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

Re: Need some info before i start making Java game

Posted 03 April 2012 - 04:10 AM

Ok, I benchmarked all three (Bewarned I have no idea how to properly benchmark). I averaged how long it took to

	
@Override
	public void paint(Graphics g)
	{
		g.drawString("Hello People", 50, 50);
		g.drawString("Hello People", 150, 50);
		g.drawString("Hello People", 250, 50);
		g.drawString("Hello People", 50, 150);
		g.drawString("Hello People", 50, 250);
	}



JPanel in JFrame was about 40k
Canvas in JFrame was about 40k
JFrame was about 43k

But I wouldn't trust me personally =P

I would just use JPanel, since it gives you the ability to more easily change the GUI. You might want to find an external game/graphics library though as they will likely be faster than what these are.
Was This Post Helpful? 0
  • +
  • -

#5 TheCompBoy   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Need some info before i start making Java game

Posted 03 April 2012 - 06:28 AM

Have you got any recomendations for one of theese libraries?
I only know one and thats LWJGL or something like that. Never realy tried it tho.
Was This Post Helpful? 0
  • +
  • -

#6 Mylo   User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

Re: Need some info before i start making Java game

Posted 03 April 2012 - 06:54 AM

I've never used another library, so I can't recommend anything. There is Slick2D, JOGL, and lwjgl as far as I know. There is also JMonkeyEngine if that interests you.
Was This Post Helpful? 0
  • +
  • -

#7 Serapth   User is offline

  • D.I.C Head

Reputation: 53
  • View blog
  • Posts: 153
  • Joined: 17-August 11

Re: Need some info before i start making Java game

Posted 03 April 2012 - 07:51 AM

View PostTheCompBoy, on 03 April 2012 - 01:28 PM, said:

Have you got any recomendations for one of theese libraries?
I only know one and thats LWJGL or something like that. Never realy tried it tho.



Most of the technical information you need about getting started with Java is available in this guide. For a 2D game, Slick2D is probably the ideal starting point.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1