Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (306)
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  Discussions / General Discussions / Re: Managing gamestates and entities, singletons on: 2013-04-12 12:33:50
Quote
Who actually unit-tests game code anyway?
Well I hope some people do Smiley

Quote
And what makes unit-testing a singleton particularly difficult?
When it comes to unit testing you need a clearly defined state of the class you want to test.
When not using a singleton, a simple
1  
new Foo();
provides you a fresh instance and a clean state.

But how can you ensure that for a singleton?
By definition there is only one instance of it and you can not be sure that it's state is what you expect it to be which makes testing it very very hard and error prone.
So your only chance would be to implement a method to reset the state of your singleton which again is error-prone.
2  Discussions / General Discussions / Re: Managing gamestates and entities, singletons on: 2013-04-11 23:10:49
You should avoid singletons wherever you can.
The singleton is reasonable called an anti pattern.

How would you unit-test a singleton?
3  Discussions / General Discussions / Re: why are people trying to use Java2D to make games? on: 2013-04-11 22:54:15
I just started to port a game from Flash to Java and when I started to port the code I already knew that the rendering part should be separated as much as possible (which it should be anyway) so I could decide later wheter to use Java2D, opengl, a printer or whatever.

So in my opinion the question about wheter to use Java2D to make games or not should be wheter or not to use Java2D for the rendering.
Java2D is not about game programming, it is about image processing (which it seems to do very well).

It is perfectly valid to use Java2D for your rendering.
And if you have separated the rendering from the rest of the game it should be no problem to switch from the Java2D API to some OGL API.
Same applies for the inputs btw.
4  Java Game APIs & Engines / Java 2D / Re: Event handling on: 2013-02-22 09:16:14
Thank you very much BoBear2681,
so basicly I need to implement the Observer Pattern by myself given the interface provided by Java.
While this is exactly what I have been looking for, I wonder why(if) there isn't any implementation but only the private field :/.
However, this helped me a lot Smiley
5  Java Game APIs & Engines / Java 2D / Event handling on: 2013-02-21 20:26:51
Hi,

I am actually not sure if this is the right place for my question but I probably will notice if not.
I come from an ActionScript background and am now dealing with Java to which I would like to port some graphical stuff I have made in "Flash" before.
The rendering is no problem for me at all but which makes me some headache is the way events are handled in Java because I have some swing gui that interacts with my model.

For instance given a custom GUI component (which extends JPanel) is composed of two other GUI components:JLabel and JButton.
If the user clicks on the JButton instance I would like to now the state of the JLabel (from a parent component which instanciated my custom component) without nowing much about the custom component (loose coupling).

So imho it would be the best solution to forward the new state(in this case it is the String of the label) as part of the custom event.

In ActionScript I couldy easily dispatch an custom event like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
class MyCustomComponent extends Sprite {
  private const myButton : MyButton = new Button();

  public function MyCustomComponent() {
    myButton.addEventListener(MouseEvent.CLICK, onButtonClick);
  }

  private function onButtonClick(event : MouseEvent) : void {
    dispatchEvent(new CustomEvent("change", "new string"));
  }
}


Another GUI component could handle events of MyComponent like this:
1  
2  
var myCustomComponent : MyCustomComponent = new MyCustomComponent();
myCustomComponent.addEventListener("change", onCustomComponentChange);


In onCustomComponentChange I then could handle the changed state of the component.

So how is this solved "correctly" in Java?

Unfortunately it seems that I can not dispatch custom events that forward objects to the listener.
I thought about some objective c delegate solution:
1  
myCustomComponent.delegate = myDelegate;

where the delegate needs to implement some component specific callbacks.
But this smells boilerplate.

Maybe I have missed something fundamental?

Thank you for your time, any help is appreciated Smiley
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
BrassApparatus (9 views)
2013-06-19 08:52:37

NegativeZero (14 views)
2013-06-19 03:31:52

NegativeZero (17 views)
2013-06-19 03:24:09

Jesse_Attard (20 views)
2013-06-18 22:03:02

HeroesGraveDev (62 views)
2013-06-15 23:35:23

Vermeer (61 views)
2013-06-14 20:08:06

davedes (61 views)
2013-06-14 16:03:55

alaslipknot (55 views)
2013-06-13 07:56:31

Roquen (77 views)
2013-06-12 04:12:32

alaslipknot (60 views)
2013-06-10 19:30:18
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
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!