Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
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   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JInput / Re: Controller connection state not properly recognized on: 2011-05-15 21:08:33
While I've only been here shortly, and not in depth, I think that JInput not detecting if a controller was unplugged or plugged was a recurring problem. So far as I can tell (someone can correct me if I'm wrong) this thread has a solution with the last post also being a solution which no one has expanded on though.

Yes thanks a lot that works! I'm using it like that:
1  
2  
3  
private Controller cs[],ctrl;
cs = new DirectAndRawInputEnvironmentPlugin().getControllers();
// for() loop to assign the desired controller to ctrl


The problem is that it's too damn slow. I'll see what I can do to speed it up, either using another timer for the enviroment check or catching the "Failed to poll device" exception. By the way, is that an exception I can catch? Who throws it?
2  Java Game APIs & Engines / JInput / Controller connection state not properly recognized on: 2011-05-10 01:40:23
Hi all.

I'm developing a program to control a robot with a gamepad as a graduation task. It works well under a controlled enviroment, but I want to make the program be aware whether the controller is connected or not. The code is not running so well, and I'm not too good at debugging with NetBeans, so I want to know if you can help me with this. The only conclusion I could gather is that he keeps doing what he was doing before after I connected/disconnected the controller, but he will know if the controller is connected or not at the beginning of execution.

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  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;
import javax.swing.Timer;

public class Tela extends javax.swing.JFrame {
    public Tela() {
        // initialization
       addWindowListener( new WindowAdapter() {
            public void windowClosing(WindowEvent e){
                pollTimer.stop();
                System.exit(0);
            }
        });
        startPolling();
    }
    private void startPolling(){
        ActionListener pollPerformer = new ActionListener() {
            public void actionPerformed(ActionEvent e){
                if(controle.checa() == 1){ // returns the number of Controller.Type.STICK or Controller.Type.GAMEPAD controllers connected
                   // interface update
               }else if(controle.checa() == 0){
                    // prints that there are no controllers
               }else{
                    // prints that there are too much controllers
               }
            }
        };
        pollTimer = new Timer(DELAY, pollPerformer);
        pollTimer.start();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code"> // NetBeans generated code for interface elements
   // </editor-fold>                        
   public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Tela().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify // NetBeans generated code for interface elements
   // End of variables declaration
   private Controle controle = new Controle(); // class wrapped around JInput
   private Timer pollTimer;
    private static final int DELAY = 20;
}

Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

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

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

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

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

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

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

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

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

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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