Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  here some starter code :)  (Read 4102 times)
0 Members and 1 Guest are viewing this topic.
Offline aNt

Senior Member




AFK


« Posted 2003-08-15 13:25:05 »

Just thought this may help some people get started with the cool JInput action:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
import net.java.games.input.*;

public class KeyboardTest {
  Keyboard kb = null;

  public KeyboardTest() {
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cont = ce.getControllers();

    System.out.println("cont: " + cont.length);
     for (int i = 0; i < cont.length; i++) {
       if (cont[i].getType() == cont[i].getType().KEYBOARD) {
         kb = (Keyboard) cont[i];
      }
    }
    
    for(int i = 0; i < 100000; i++) {
      keyboardupdate();
    }
    
    System.out.println("done...");
  }

  public void keyboardupdate() {
    kb.poll();
    Axis[] ax = kb.getAxes();
    for (int x = 0; x < ax.length; x++) {
      float num = ax[x].getPollData();
      if (num != ax[x].getDeadZone()) {
        if (ax[x].getName().equalsIgnoreCase("key 110")) {
          System.out.println("up arrow");
        }
      }
    }
  }
}
Offline pennyweng

Innocent Bystander




Java games rock!


« Reply #1 - Posted 2003-08-15 17:44:31 »

Sorry !!...

I run the code in IDE but it can't found any "Controller".
Please tell me what's wrong?
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #2 - Posted 2003-08-16 03:06:58 »

You don't have jinput.jar installed and you don't have the native jinput plugin installed.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline TheBohemian

Junior Member




Java will rule them all!


« Reply #3 - Posted 2003-08-16 16:55:42 »

@gregorypierce:
Can you explain the deadzone thing?

I was able to build a small app using jinput that uses the keyboard and I only checked for absolute values of kb.getPollData().

for digital devices i thought it would mean:
1.0f => pressed
0.0f => unpressed

unfornately jinput's apidoc is lacking much details.

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #4 - Posted 2003-08-16 20:25:13 »

Hi
 The deadzone is used for joysticks and is the amount by which the joystick axis value can change even if the joystick is held still. If you get a joystick axis value, and it doesn't move by more than the deadzone amount, you pretend it hasn't moved, if it moves by more than the deadzone amount you accept the new position, if you calibrate a joystick under windows where you have the gui to look at axis positions, you will notice it 'twitching' about a point, the deadzone is so that the twitching doesn't show.

If that makes sense Smiley

Cheers

Endolf

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #5 - Posted 2003-08-26 12:07:09 »

Now until i manage to find the JInput docs, i'm working blind - but I tried this example code yet JInput seems to hit a null pointer deep within itself somewhere:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
Importing preferences from file: ./config.xml
java.lang.NullPointerException
      at net.java.games.util.plugins.Plugins.scanPlugins(Plugins.java:78)
      at net.java.games.util.plugins.Plugins.<init>(Plugins.java:73)
      at net.java.games.input.DefaultControllerEnvironment.scanControllersAt(DefaultControllerEnvironment.java:170)
      at net.java.games.input.DefaultControllerEnvironment.scanControllers(DefaultControllerEnvironment.java:162)
      at net.java.games.input.DefaultControllerEnvironment.access$000(DefaultControllerEnvironment.java:57)
      at net.java.games.input.DefaultControllerEnvironment$1.run(DefaultControllerEnvironment.java:108)
      at java.security.AccessController.doPrivileged(Native Method)
      at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:106)
      at com.vecript.core.Vecript.testJInput(Vecript.java:128)
      at com.vecript.core.Vecript.<init>(Vecript.java:121)
      at com.vecript.core.Vecript.<clinit>(Vecript.java:43)
java.lang.NullPointerException
      at net.java.games.util.plugins.Plugins.scanPlugins(Plugins.java:78)
      at net.java.games.util.plugins.Plugins.<init>(Plugins.java:73)
      at net.java.games.input.DefaultControllerEnvironment.scanControllersAt(DefaultControllerEnvironment.java:170)
      at net.java.games.input.DefaultControllerEnvironment.scanControllers(DefaultControllerEnvironment.java:164)
      at net.java.games.input.DefaultControllerEnvironment.access$000(DefaultControllerEnvironment.java:57)
      at net.java.games.input.DefaultControllerEnvironment$1.run(DefaultControllerEnvironment.java:108)
      at java.security.AccessController.doPrivileged(Native Method)
      at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:106)
      at com.vecript.core.Vecript.testJInput(Vecript.java:128)
      at com.vecript.core.Vecript.<init>(Vecript.java:121)
      at com.vecript.core.Vecript.<clinit>(Vecript.java:43)
cont: 0
java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
      at com.vecript.core.Vecript.keyboardUpdate(Vecript.java:152)
      at com.vecript.core.Vecript.testJInput(Vecript.java:143)
      at com.vecript.core.Vecript.<init>(Vecript.java:121)
      at com.vecript.core.Vecript.<clinit>(Vecript.java:43)
Exception in thread "main"


I'm using the latest nightly build, is this known to be stable or should i be trying an older version? How stable is JInput at this time (both in terms of crashes and in terms of API changes)?

Any help appreciated.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #6 - Posted 2003-08-26 12:39:24 »

Hi
 It looks liek there are two problems there, the null pointer is one, but the other is the fact that its using the DefaultEnvironmentPlugin, which suggests you don't have the native part in you java library path.

HTH

Endolf

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #7 - Posted 2003-08-26 13:15:18 »

So how do i fix the DefaultEnvironmentPlugin to something else? I've currently got: jutils.jar, jinput.jar, dxinput.jar in the classpath, and dxinput.dll in the path. I'm surprised theres no jinput.dll like Jogl and Joal, but theres nothing else lying around in the binarys .zip file.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #8 - Posted 2003-08-26 16:25:02 »

try java <classpath> -Djava.library.path=<path to directory with dxinput.dll in it> <classname>

also, the dxinput.jar needs to be in a directory called controller, relative to where ever you are running from.

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #9 - Posted 2003-08-27 12:04:18 »

I managed to get this working, turns out i was still using the early unofficial build of the Jogl/Joal/JInput (the jsr138.jar file) which was the reason beind the null pointer exception. A quick switch to the latest Jogl and JInput fixed this problem.

I also needed to change the dxinput.jar to a controller dir as you mentioned. I'm not too happy with this, it mucks up my carefully crafted directory structure Angry but it will do for now. I assume that JInput is doing some sort of fancy dynamic loading and expects it to be in this location? Is is possible to alter this behaviour?

Edit: Ah I see the PluginClassLoader scans a directory to load the plugin classes. The 'controller' string sits hardcoded in the source, but i'm unsure how it could be made to be externally settable...? Unless it could be passed in as an argument to the api somewhere..

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #10 - Posted 2003-08-27 12:16:49 »

Hi
 It would make sense to me to see it as a system property, something like jinput.controllerPluginPath, which can be set either in a proeprties file or with the -D flag. defaulted to controller of course

Cheers

Endolf

Offline Jeff

JGO Coder




Got any cats?


« Reply #11 - Posted 2003-09-02 18:28:35 »

Quote
try java <classpath> -Djava.library.path=<path to directory with dxinput.dll in it> <classname>

also, the dxinput.jar needs to be in a directory called controller, relative to where ever you are running from.


Or it can be in a directory called controller in the right palce in your Java SDK instllation (I believe its lib\ext but I need to look to make sure.)

Isn't this documented?  I thought it was.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Jeff

JGO Coder




Got any cats?


« Reply #12 - Posted 2003-09-02 18:30:28 »

Doing an over-ride with a -D aught to be easy.

(I'd still keep the set palces as defaults if there is no over-ride property defined.)

I'm up to my waders in alligatros on server code right now, does someone else want to make that change?  Should be all of about 3 lines of code...


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #13 - Posted 2003-09-02 23:18:28 »

Hi
 I agree about how simple it should be, unless it's done when I get up (it's just gone midnight here) I will do it.

Endolf

Offline Jeff

JGO Coder




Got any cats?


« Reply #14 - Posted 2003-09-03 18:56:04 »

Thanks again End.  You're a real trooper Smiley

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #15 - Posted 2003-09-04 11:51:45 »

Hi
 Forgot yesterday, but just checked in the change,
1  
-Djinput.controllerPluginPath=<location of plugin>
will override the plugin path that is scanned for the plugin. if it's not supplied it will default to controller like before.

Endolf

Offline hbomboy

Junior Newbie




Java games rock!


« Reply #16 - Posted 2004-06-18 01:52:42 »

im not sure what happened (perhaps i triggered a debug mode in the osx install? but after running just those simple lines of code, my computer has been spitting out millions of lines of "Queue getNextEvent return value :0".  I killed the process about 4 mins ago, and its still going.  Writing that much is bound to kill any 3d app... is there a way to turn this mode off?
Offline TheBohemian

Junior Member




Java will rule them all!


« Reply #17 - Posted 2004-06-18 11:42:56 »

although jinput version number is 1.1 and contains beta in its name it is more alpha. diagnostic messages are spilled out on every platform. Sad

at least you are trying the stuff and comment here. IMHO I think a lot of people just lose interest after realizing that Jinput isn't that shiny now.

if you want to participate feel free to enter the suggestion's thread: http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=jinput;action=display;num=1087176216


cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Pages: [1]
  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.

Riven (12 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (10 views)
2014-07-29 10:59:34

E.R. Fleming (26 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!