EnderGT
Jr. Member   Posts: 98
|
 |
«
Reply #30 on:
2008-12-12 12:42:43 » |
|
Hmm, that's interesting - I wonder if that is a quirk of a particular implementation, or is a documented piece of functionality. What is your main Container subclassing? Applet, Frame or JFrame?
To date, it's always been JFrame, and it's Sun's JRE 1.6.0_03. Edit: I just did a test with the game I'm currently implementing. It extends JFrame, and calls enableEvents(0x30) - that's AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK, for those not familiar. I added an override for processKeyEvent, and sure enough I'm receiving key events even though they were not explicitly enabled,
|
|
|
|
|
rdcarvallo
Sr. Member   Posts: 300
2D Java games forever!
|
 |
«
Reply #31 on:
2008-12-13 08:05:07 » |
|
I tried to delete the enableEvents() call, but the game stopped working, could you test comenting your code and looking if the keyboard works?? (I'm in jdk1.6.0_11)
|
|
|
|
|
Ranger
Sr. Member   Posts: 340 Medals: 1
|
 |
«
Reply #32 on:
2008-12-13 10:38:40 » |
|
Hmm, that's interesting - I wonder if that is a quirk of a particular implementation, or is a documented piece of functionality. What is your main Container subclassing? Applet, Frame or JFrame?
I'm subclassing JApplet. Java 1.6.0_10 I found the Java code that enables the key events. It's in the first line of the JComponent constructor 1 2 3 4 5 6
| public JComponent() { super(); enableEvents(AWTEvent.KEY_EVENT_MASK); |
Looks like it has been there since Java 1.3.
|
|
|
|
|
Games published by our own members! Go get 'em!
|
|
Abuse
JGO Kernel      Posts: 1866 Medals: 5
falling into the abyss of reality
|
 |
«
Reply #33 on:
2008-12-13 14:00:52 » |
|
I'm subclassing JApplet. Java 1.6.0_10 I found the Java code that enables the key events. It's in the first line of the JComponent constructor 1 2 3 4 5 6
| public JComponent() { super(); enableEvents(AWTEvent.KEY_EVENT_MASK); |
Looks like it has been there since Java 1.3. Ah, good find. Though, that doesn't explain the behaviour of Applet/JApplet/Frame or JFrame? Unless ofcourse Container has the same call in it's constructor? (too lazy to start Eclipse & check myself  ) Logically, I guess this means that if you ever call disableEvents(AWTEvent.KEY_EVENT_MASK) on a JComponent, it will have the side-effect of causing accessibility bindings(what are those???) to stop working.... Something the fixer should of thought about when they put that hack fix in  So, does the Apple JRE also contain this same quirk?
|
|
|
|
|
appel
JGO Wizard     Posts: 1477 Medals: 23
I always win!
|
 |
«
Reply #34 on:
2008-12-13 23:31:00 » |
|
Tip of the day: BULLET/LASER/MACHINE GUN EFFECTAh, those dreaded bullets that your player or baddies generates. Takes up a lot of code do to all that bullet management code! E.g., making array for storing bullets, position, where they are going, do collision detection etc? SIMPLE SOLUTION! Create a STROKE that alternates: 1 2 3 4 5
| BasicStroke bulletStrokes[] = { new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] {2, 26}, 0), new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] {2, 26}, 7), new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] {2, 26}, 14) }; |
Then you can simply alternate the index to the bulletStrokes array in order to animate. The above array has the exactly same bullet, but the last parameter tells how it's shifted in order to make it animate. 2 strokes are enough if it's some sort of machine gun effect. Now, let's say you have some sort of tank positioned at x,y and it's supposed to shoot shots at a enemy tank positioned at a,b you can simply: 1 2
| g.setStroke(bulletStrokes[currentStroke]); g.drawLine(x,y, a,b); |
TA DA! That's all the bullet code you need. You can tweak around with the BasicStroke objects to create some nice effects, e.g. if you wish to create lasers or something like that. Of course this doesn't solve all problems, but for many this will help.
|
|
|
|
Ranger
Sr. Member   Posts: 340 Medals: 1
|
 |
«
Reply #35 on:
2008-12-14 03:07:51 » |
|
Ah, good find. Though, that doesn't explain the behaviour of Applet/JApplet/Frame or JFrame? Unless ofcourse Container has the same call in it's constructor? (too lazy to start Eclipse & check myself  ) JApplet calls setRootPane(createRootPane()); in its constructor. JRootPane inherits from JComponent.
|
|
|
|
|
rdcarvallo
Sr. Member   Posts: 300
2D Java games forever!
|
 |
«
Reply #36 on:
2008-12-14 10:19:25 » |
|
So.. I will have to change my awt.Frame for swing.JFrame, to get the keyboard enabled?
|
|
|
|
|
Ranger
Sr. Member   Posts: 340 Medals: 1
|
 |
«
Reply #37 on:
2008-12-14 10:50:33 » |
|
So.. I will have to change my awt.Frame for swing.JFrame, to get the keyboard enabled?
This will work on the Sun JVM. Not sure about Mac, IBM, and others. Personally, I've played it safe and left the enableEvents call in.
|
|
|
|
|
jojoh
JGO Ninja    Posts: 554 Medals: 6
games4j.com
|
 |
«
Reply #38 on:
2008-12-18 10:57:02 » |
|
ProGuard came out with a new version (4.3) just a few days ago http://proguard.sourceforge.net/Not sure if update will help any 4K games, but still nice to have the latest.
|
|
|
|
Eli Delventhal
« League of Dukes » JGO Kernel      Posts: 3574 Medals: 44
Game Engineer
|
 |
«
Reply #39 on:
2009-01-03 21:15:43 » |
|
I think I just decided I don't want to do this anymore because every single obfuscater I try to use seems to get some error or another. They're basically a ginormous pain to use, and nobody seems to have put any straight up clear examples of their use. Is there something I'm missing? You all are able to say "this saved X bytes!" etc. but I can't do that because I don't know how small it will get with all those optimization programs.  So can anyone help me out? It doesn't seem like it should take 20 minutes every single build to compress everything and see how small it actually is supposed to be. I mean my game is like 400 lines and I'm using 3,204 bytes, so my code is certainly written in a space-saving fashion but I still don't have an obfuscater working. Hm.
|
See my work:OTC Software<br /> Currently Working On:Secret project... I edit JGO in production, because I simply don't waste time writing bugs
|
|
|
Games published by our own members! Go get 'em!
|
|
Morre
JGO Ninja    Posts: 507
I'm Dragonene on IRC.
|
 |
«
Reply #40 on:
2009-01-04 16:42:31 » |
|
If you just want a way to get a feeling for how big your program is, I recommend using JOGA. It won't get quite as small as the output JAR from, say, moogie's tool, but it will give you a good idea of how big it'll be. Personally, I aim for a JOGA size a few hundred bytes over 4000 (perhaps 4300) - this'll usually let me get it down to under 4096 with moogie's tool.
If you're having problems getting JOGA to work, try disabling the settings for optimizing slot width and slot order under "Optimizations" -> "Byte code optimizations". These sometimes corrupts the output JAR. Also, I recommend doing initial compression (from .class to .zip/.jar) with window's built-in compressed folder system, it's usually better than for example winzip.
|
|
|
|
|
|
CaptainJester
JGO Neuromancer     Posts: 1138 Medals: 8
Make it work; make it better.
|
 |
«
Reply #42 on:
2009-01-19 12:11:09 » |
|
Added a new entry to the WiKi. I thought I would post it here because most people probably don't check the WiKi regularly. Reduce else clause usage where possible. Going from this 1 2 3 4 5 6
| if((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) == KeyEvent.SHIFT_DOWN_MASK) { shiftmodifier = true; } else { shiftmodifier = false; } |
to this 1 2 3 4
| shiftmodifier = false; if((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) == KeyEvent.SHIFT_DOWN_MASK) { shiftmodifier = true; } |
saved me 4 bytes in the final compressed archive.
|
|
|
|
irreversible_kev
Full Member   Posts: 174
|
 |
«
Reply #43 on:
2009-01-19 12:13:55 » |
|
saved me 4 bytes in the final compressed archive.
I must have this wrong but can't you do 1
| shiftmodifier = ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) == KeyEvent.SHIFT_DOWN_MASK); |
instead?
|
|
|
|
|
CaptainJester
JGO Neuromancer     Posts: 1138 Medals: 8
Make it work; make it better.
|
 |
«
Reply #44 on:
2009-01-19 12:15:41 » |
|
Can't you do 1
| shiftmodifier = ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) == KeyEvent.SHIFT_DOWN_MASK); |
instead? Oops.  Yes of course. However in non boolean cases this will help. I will change the example to a non boolean one to avoid confusion.
|
|
|
|
pjt33
JGO Strike Force    Posts: 913 Medals: 17
|
 |
«
Reply #45 on:
2009-01-19 17:24:41 » |
|
I must have this wrong but can't you do 1
| shiftmodifier = ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) == KeyEvent.SHIFT_DOWN_MASK); |
instead? You may also be better off doing 1
| shiftmodifier = ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) != 0); |
|
|
|
|
|
ido
Jr. Member   Posts: 95
|
 |
«
Reply #46 on:
2009-03-27 06:29:59 » |
|
This is all really great, thanks a lot everyone for posting! I will try to use the template & the tips provided here soon, when I try my first 4k game 
|
|
|
|
|