Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  LWJGL Keyboard, what's going on?  (Read 903 times)
0 Members and 1 Guest are viewing this topic.
Offline PaidGEEK

Senior Member


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« Posted 2013-01-28 16:22:36 »

Hello!
Quick question! I have player input setup like this:
1  
2  
3  
4  
5  
boolean keyUp = Keyboard.isKeyDown(Keyboard.KEY_UP)
...
if(keyUp){
    //move code
}

And a bit later:
1  
2  
3  
4  
5  
while(Mouse.next()){
   if(Mouse.isButtonDown(0)){
      //fire button (boom boom)
  }
}

So what happens is, if player holds UP key to run and presses mouse button to fire, movement stops. In order to run again, player must press up key again, running while shooting is impossible.
Why do keys get reset that way?

Improvisational programmer.
Offline DazKins
« Reply #1 - Posted 2013-01-28 16:48:27 »

It's todo with the way how when you call Mouse.next() or Keyboard.next() it polls the event so it cannot be used again that tick.

The way i Would solve that particular issue is to create a seperate input class like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public class InputHandler {
   
   public boolean keysStream[] = new boolean[65536];
   
   public void tickInput(){
      while(Keyboard.next()){
         if(Keyboard.getEventKeyState()){
            keysStream[Keyboard.getEventKey()]=true;
         }else{
            keysStream[Keyboard.getEventKey()]=false;
         }
      }
      while(Mouse.next()){
                       //code here
               }

   }
}

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline PaidGEEK

Senior Member


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« Reply #2 - Posted 2013-01-28 17:25:53 »

Ah I see. Gonna implement it straight away. Thanks!

Improvisational programmer.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Sickan

Senior Member


Medals: 9



« Reply #3 - Posted 2013-01-28 17:29:08 »

1  
new boolean[65536];

This basically allocates 64 kilobytes of memory. I can't help but feel like it's wasteful.
Offline PaidGEEK

Senior Member


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« Reply #4 - Posted 2013-01-28 17:30:34 »

So I could just use the keys I need.

Improvisational programmer.
Offline DazKins
« Reply #5 - Posted 2013-01-28 17:36:55 »

Yes you can, I only put that as that will be able to get button presses for all keyboards, e.g chinese and swedish ones as the different characters have different codes

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline Sickan

Senior Member


Medals: 9



« Reply #6 - Posted 2013-01-28 17:39:23 »

There's probably some great container for these kinds of things, but I have no idea.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #7 - Posted 2013-01-28 18:36:03 »

I think you're looking for this class.  

First person who complains about the overhead is going to get smacked.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2013-01-28 18:41:54 »

I think you're looking for this class.
I'll preemptively smack you for the broken link.

First person who complains about the overhead is going to get smacked.
Why is CPU overhead (Set<Integer> + autoboxed Integer instances) better than memory overhead (boolean[])?

Let him use his boolean[], and trade off memory for performance, or convenience for that matter.

And why do we have this discussion again? Clueless

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Sickan

Senior Member


Medals: 9



« Reply #9 - Posted 2013-01-28 18:44:42 »

I wish they would have included variations of the collections classes that are tailored towards the primitives as well. Or just not failed so badly with generics.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 202



« Reply #10 - Posted 2013-01-28 19:58:02 »

I fixed the link.  Smack SMF for freaking out when you put the URL in quotes.  Freakin BBCode.

Got an actual performance issue with a Set, do we?  If you really need primitive collections, try Trove.  Beyond that, screw it, I too am tired of having this argument.
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2013-01-29 01:45:58 »

No please do have this argument, it sounds quite educational.

*Grabs popcorn*

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.

atombrot (25 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

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

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

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!