Results 1 to 2 of 2
- 11-26-2011, 09:42 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 14
- Rep Power
- 0
Can't figure out how to create a keyboard class for lwjgl
I'm very new to java. I'm trying to make a very basic game engine as a way to help me learn the language. Of course, before I can make an infinite loop, I have to know how to get input from the keyboard so that I can break out of it.
Unfortunately, that's where the problem is. I can't seem to get a key-press input to work. I'm getting an error saying:
I've tried making a new variable and setting it to "new Mouse();", but that didn't do anything. Can anyone help me?Java Code:Caused by: java.lang.IllegalStateException: Keyboard must be created before you can query key state at org.lwjgl.input.Keyboard.isKeyDown(Keyboard.java:398) at Runner.<clinit>(Runner.java:8)
Here is my Runner.class:
//imports
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
And in case my "General_Mob" class is causing some sort of error, here's the source for that too:Java Code:public class Runner { //declare variables public static General_Mob Mob1 = new General_Mob(); //create a new instance of General_Mob called "Mob1" static boolean keyDown = Keyboard.isKeyDown(Keyboard.KEY_X); //methods public static void main(String[] args){ System.out.println("Check. Check. Check."); Mob1.Create(); for (;keyDown;){ goAround(Mob1); } } public static void goAround(General_Mob Mob1){ Mob1.goAround(); } }
Java Code://imports import java.lang.Math; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; public class General_Mob { //declare variables private static double x, y, z, vspeed, hspeed, zspeed, friction; public static int xround, yround, zround; //methods public static void Create() { x = 0; y = 0; vspeed=3; hspeed=2; zspeed=1; friction=2; } public static void goAround(){ //First things first: Update the mob's position, speed, and friction. crunchPhysics(); System.out.println("X:" + xround + " Y:" + yround + " Z:" + zround); } public static void crunchPhysics(){ //Slow the mob down based on its friction if (hspeed <=0){ hspeed+=friction; } else{ hspeed-=friction; } if (vspeed <=0){ vspeed+=friction; } else{ vspeed-=friction; } if (zspeed <=0){ zspeed+=friction; } else{ zspeed-=friction; } //Move the mob based on its speed. x += hspeed; y += vspeed; z += zspeed; //Round the positions to integers so that they can be drawn on the screen. After all, how can you draw something that's .01 pixels? xround=(int) Math.rint(x); yround=(int) Math.rint(y); zround=(int) Math.rint(z); } }
- 11-27-2011, 12:39 AM #2
Similar Threads
-
LWJGL Collision Detection
By Furyright in forum Java 2DReplies: 1Last Post: 10-09-2011, 06:48 AM -
lwjgl help PLEASE!
By Brandon in forum New To JavaReplies: 1Last Post: 10-06-2011, 06:11 AM -
Can't figure out how to get the info from class definition to driver program
By gnng in forum New To JavaReplies: 10Last Post: 04-20-2011, 02:03 AM -
LWJGL: Camera + Block Collision
By Aaron in forum New To JavaReplies: 6Last Post: 11-14-2010, 09:53 PM -
Keyboard Input In A Seperate Class?
By FatalSylence in forum New To JavaReplies: 6Last Post: 10-12-2010, 05:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks