processEvent vs processKeyEvent

Some little questions :stuck_out_tongue:

For an action (to name it) keyboard based game (5 game keys plus escape and maybe pause) it’s better to use processEvent or processKeyEvent (in terms of keeping the class small) ? In the little tests I’ve done it seems processKeyEvent is lighter, but I’m not really sure.

Any hint to how to get the smallest double-buffering technique ?

Thanks for your help.

Automate your builds:

  1. compile
  2. zip it

Then compare the file-sizes of the zips of different versions.

There is no other way to find out. To answer your question, we would have to do the very same thing.

The extra 3 bytes you spend on the method name, are more than made up for with the extra discrimination you get on the parameter. (i.e. you are guaranteed the event will be a KeyEvent, so don’t have to do a check yourself.)

[quote=“x30ice,post:1,topic:25906”]
WARNING!
Danger Will Robinson, DANGER!

You’re micro-optimizing. All you’re going to get for your troubles is a lot of pain, anguish, and impossible to maintain code. Look for the areas where you can get BIG savings, not little ones.

To repeat a famous quote:

First rule of optimization: Don’t do it.
Exception for experts only: Don’t do it. Yet.

[quote=“x30ice,post:1,topic:25906”]
If it’s an action game, just setup the BufferStrategy and be happy. If it’s a non-action game, Swing will do it for you automatically.

See my thread “Source for smallest game loop” for and example game loop.

Marry me.

Sorry, my wife won’t let me. :stuck_out_tongue: :smiley: