Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
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 3851 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();
    }
}
Online kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« 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: 743
Projects: 4
Exp: 16 years


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
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


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
Offline h3ckboy

JGO Coder


Medals: 5



« 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: 743
Projects: 4
Exp: 16 years


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


Medals: 145
Projects: 4
Exp: 14 years


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: 743
Projects: 4
Exp: 16 years


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

 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
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!