Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
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 1479 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.
canvas.addMouseWheelListener(new MouseWheelListener() {
   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.
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: 388
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
public void keyTyped(KeyEvent e) {

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

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

JGO Kernel

Medals: 388
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

Junior Devvie

Medals: 6
Exp: 4 years

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

Riven (21 views)
2015-07-03 11:22:16

deepthought (45 views)
2015-06-30 15:39:44

deepthought (49 views)
2015-06-30 15:39:09

deepthought (62 views)
2015-06-30 15:36:52

Za\'Anzabar (31 views)
2015-06-29 05:44:54

TritonDreyja (45 views)
2015-06-24 17:10:40

CopyableCougar4 (44 views)
2015-06-23 00:34:45

BurntPizza (48 views)
2015-06-21 20:36:46

cookiecompiler (89 views)
2015-06-11 15:42:53

cookiecompiler (53 views)
2015-06-11 15:41:14
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 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‑
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!