Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  Slick2D Two Input Questions and More  (Read 1212 times)
0 Members and 1 Guest are viewing this topic.
Offline Vladiedoo
« Posted 2012-06-19 22:46:30 »

Hi, back when I was using Java2D I used this code to listen to the mousewheel.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
canvas.addMouseWheelListener(new MouseWheelListener() {
        @Override
   public void mouseWheelMoved(MouseWheelEvent e) {
      if (-e.getWheelRotation() == 1) {
         //Do stuff
      } else if (-e.getWheelRotation() == -1) {
         //Do stuff
      }
   }
});

How do I listen to the mouse wheel with Slick2D? I have this but I can't find an option for mouse wheel.
1  
2  
3  
4  
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
   Input input = gc.getInput();
        //input.    <---- I did input.addMouseListener(new MouseWheelListener) { } but had errors with that
}


My second issue I'm having with input is when the user hits keys on the keyboard the program registers it each time it updates the game loop (I currently have it set to 60fps). To better explain my issue: I have a main menu and when I hit the up arrow to go to the next option it jumps a couple of options because I didn't click on the up arrow super quickly. I could sleep the Thread but that would pause the whole game. Does someone know how I can fix this? Here is some code to show what I'm doing. Fixed! x), I changed it to input.isKeyPressed

When moving sprites how do I use delta time? I've seen tutorials that use delta time and I'm not quite sure why I'd need to. For example I've seen x += delta * 0.1 * 1 , why can't I just do x += movementSpeed;

Last question, why isn't v-sync standard? Is there some reason on why I shouldn't use v-sync?
Thank you so much for your time.
Offline davedes
« Reply #1 - Posted 2012-06-20 00:58:47 »

Override mouseWheelMoved(int) in BasicGame or BasicGameState.

delta is the amount of time that has elapsed since the last frame. We use it mainly for two reasons: (1) to ensure consistent play speed across platforms and (2) to reduce stuttering and make for smoother movement.

Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2012-06-20 01:00:46 »

I'm not too familiar with Slick2D but I'm pretty sure if you look around at the JavaDocs/Input classes/Tutorials/billions of resources, you will find your answer Smiley
EDIT: davedes stole my thunder! Angry

And for deltaTime, x += movementSpeed depends on your update-rate to be exactly 60 times per second. If for some reason it slows down, the game play will slow down. You multiply by your deltaTime to make sure no matter how many times update is called, the game play will stay the same speed.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Vladiedoo
« Reply #3 - Posted 2012-06-20 04:27:43 »

Ah, thanks for the help davedes and ra4king. So that means I'd want to have everything be affected by delta then? Such as a moving bullet and scrolling text? Also what about V-sync? Thanks again for the help though.

Also how do I detect a Tilde with Slick2D? I was able to do it with Java2D by doing
1  
2  
3  
public void keyTyped(KeyEvent e) {

      if (e.getKeyChar() == '`')


my best guess was doing this but alas it doesn't work
1  
2  
3  
4  
   public void update(GameContainer gc, StateBasedGame sbg, int delta)
         throws SlickException {
                Input input = gc.getInput();
                if (input.equals("`")){
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2012-06-20 17:25:32 »

You can't compare the Input object to a String XD

You've got to use event methods in Slick2D just like Java2D.

Offline Magn919
« Reply #5 - Posted 2012-06-20 18:00:46 »

Override keyPressed(int key, char c) in BasicGameState or BasicGame.

the c parameter is similar to calling KeyEvent.getKeyChar() and the key parameter is similar to calling KeyEvent.getKeyCode()

For every new problem, a new source of solutions has come to exist.
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.

Longarmx (50 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (36 views)
2014-10-15 16:18:58

TehJavaDev (66 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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