Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (307)
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  
  Jinput is awsome, I want it's babies, but a slight issue ....  (Read 2981 times)
0 Members and 1 Guest are viewing this topic.
Offline CyanPrime
« Posted 2009-11-24 20:23:32 »

I tried using it on this simple code, and JInput makes the controller automatically go up and left!

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  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

 
public class Test1 extends BasicGame{
   float x = 300;
   float y = 300;
   
    public Test1()
    {
        super("Controller Test 1");
    }
 
    @Override
    public void init(GameContainer gc)
         throws SlickException {
    }
 
    public void updateControler(GameContainer gc){
       Input input = gc.getInput();

         
          System.out.println("input.isControllerUp(Input.ANY_CONTROLLER)" + input.isControllerUp(Input.ANY_CONTROLLER));
         
          if(input.isKeyDown(Input.KEY_UP) || input.isControllerUp(Input.ANY_CONTROLLER)) {
            y--;
         }
         
          else if(input.isKeyDown(Input.KEY_DOWN) || input.isControllerDown(Input.ANY_CONTROLLER)) {
            y++;
         }
   
          else if(input.isKeyDown(Input.KEY_LEFT) || input.isControllerLeft(Input.ANY_CONTROLLER)) {
            x--;
           }
         
          else if(input.isKeyDown(Input.KEY_RIGHT) || input.isControllerRight(Input.ANY_CONTROLLER)) {
            x++;
           }
    }
   
    @Override
    public void update(GameContainer gc, int delta)
         throws SlickException    
    {;
       updateControler(gc);
    }

 
    public void render(GameContainer gc, Graphics g)
         throws SlickException
    {  
       g.setColor(Color.red);
       g.fillRect(x,y,50,50);
    }
 
    public static void main(String[] args)
         throws SlickException
    {
         AppGameContainer app =
         new AppGameContainer(new Test1());
 
         app.setDisplayMode(800, 600, false);
         app.start();
    }
}
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #1 - Posted 2009-11-24 20:37:02 »

Way to make friends and influence people! Smiley

The problem could be in Slick also?

Kev

Offline CyanPrime
« Reply #2 - Posted 2009-11-24 20:37:54 »

Way to make friends and influence people! Smiley

The problem could be in Slick also?

Kev
But Slick is too awesome to have problems  Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #3 - Posted 2009-11-24 20:43:23 »

so... it had been mentioned in this forum that some controllers have an initial (non zero) value. Once you move them once, they work properly.

So... maybe as an initial step:
1. iterate over all controllers
2. assume nobody is touching any controllers
3. record the current values

And for the game-loop:
1. check to see the current value of each controller
2. if it's NOT the same as the initial value, START handling the input events

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #4 - Posted 2009-11-24 20:43:38 »

*bump*

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline h3ckboy
« Reply #5 - Posted 2009-11-24 21:10:06 »

riven, why did you bump 30 seconds(literaly) after your last post?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #6 - Posted 2009-11-24 21:11:42 »

Because CyanPrime is *bumping* his threads all the time, which is utterly useless and annoying.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline CyanPrime
« Reply #7 - Posted 2009-11-24 22:01:02 »

And for the game-loop:
1. check to see the current value of each controller
2. if it's NOT the same as the initial value, START handling the input events
If I check to make sure they're not going up and left before I do anything they won't be able to go up and left x_x
Offline Nate

JGO Wizard


Medals: 88
Projects: 3


Esoteric Software


« Reply #8 - Posted 2009-11-25 01:31:11 »

If I check to make sure they're not going up and left before I do anything they won't be able to go up and left x_x
Read it again. Smiley

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #9 - Posted 2009-11-25 02:13:11 »

Read it again. Smiley

Without capitals, there would have been no hope!

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline endolf
« League of Dukes »

JGO Coder


Medals: 4
Projects: 1


Current project release date: sometime in 3003


« Reply #10 - Posted 2009-11-25 08:00:15 »

Some controllers seem to have non zero values until the device is moved. Not all. But some. I have no idea why. What device is showing this issue to you?.

As Riven suggested, you can work around the OS wierdness by assuming the first polled value is not always right, and wait for a controller to change before paying it any attention. I've not yet seen any mice or keyboards do this, only game controllers, so that should make life easier.

You could also try using the newer event based interface instead of the old one, I have no idea if that will help as none of my devices show the problem.

HTH

Endolf

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

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
mrbenebob (19 views)
2013-06-19 14:55:23

BrassApparatus (29 views)
2013-06-19 08:52:37

NegativeZero (32 views)
2013-06-19 03:31:52

NegativeZero (34 views)
2013-06-19 03:24:09

Jesse_Attard (39 views)
2013-06-18 22:03:02

HeroesGraveDev (75 views)
2013-06-15 23:35:23

Vermeer (76 views)
2013-06-14 20:08:06

davedes (77 views)
2013-06-14 16:03:55

alaslipknot (69 views)
2013-06-13 07:56:31

Roquen (92 views)
2013-06-12 04:12:32
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
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!