Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Links, tips and goodies  (Read 21435 times)
0 Members and 1 Guest are viewing this topic.
Offline EnderGT

Junior Member





« Reply #30 - Posted 2008-12-12 18: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,
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #31 - Posted 2008-12-13 14: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)
Offline Ranger
« Reply #32 - Posted 2008-12-13 16: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();
   // We enable key events on all JComponents so that accessibility
  // bindings will work everywhere. This is a partial fix to BugID
  // 4282211.
       enableEvents(AWTEvent.KEY_EVENT_MASK);


Looks like it has been there since Java 1.3.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #33 - Posted 2008-12-13 20: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();
   // We enable key events on all JComponents so that accessibility
  // bindings will work everywhere. This is a partial fix to BugID
  // 4282211.
       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 Cheesy)

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 Roll Eyes

So, does the Apple JRE also contain this same quirk?

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline appel

JGO Wizard


Medals: 49
Projects: 4


I always win!


« Reply #34 - Posted 2008-12-14 05:31:00 »

Tip of the day:

BULLET/LASER/MACHINE GUN EFFECT


Ah, 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]); // currentStroke is an index for animation purposes.
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.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Ranger
« Reply #35 - Posted 2008-12-14 09: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 Cheesy)

JApplet calls setRootPane(createRootPane()); in its constructor.  JRootPane inherits from JComponent.
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #36 - Posted 2008-12-14 16:19:25 »

So.. I will have to change my awt.Frame for swing.JFrame, to get the keyboard enabled?
Offline Ranger
« Reply #37 - Posted 2008-12-14 16: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.
Offline jojoh

JGO Knight


Medals: 5
Projects: 7


games4j.com


« Reply #38 - Posted 2008-12-18 16: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.

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #39 - Posted 2009-01-04 03: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.  Undecided

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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Morre

JGO Knight


Medals: 2
Projects: 10


I'm Dragonene on IRC.


« Reply #40 - Posted 2009-01-04 22: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.

Offline pjt33
« Reply #41 - Posted 2009-01-10 23:15:43 »

For anyone else developing under Linux and finding it hard to Google up a link to the port of kzip: http://www.jonof.id.au/index.php?p=kenutils
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2


Make it work; make it better.


« Reply #42 - Posted 2009-01-19 18: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.

Offline irreversible_kev

Junior Member





« Reply #43 - Posted 2009-01-19 18: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?
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2


Make it work; make it better.


« Reply #44 - Posted 2009-01-19 18:15:41 »

Can't you do

1  
shiftmodifier = ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) == KeyEvent.SHIFT_DOWN_MASK);


instead?


Oops.  Undecided

Yes of course.   However in non boolean cases this will help.  I will change the example to a non boolean one to avoid confusion.


Offline pjt33
« Reply #45 - Posted 2009-01-19 23: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);
Offline ido

Junior Member





« Reply #46 - Posted 2009-03-27 11: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 Smiley

Pages: 1 [2]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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 (75 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

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
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!