Omnimaga
General Discussion => Technology and Development => Computer Programming => Topic started by: ben_g on February 19, 2013, 04:26:19 pm
-
I have a strange problem in my current code: When I call Controls.requestKeyChange from MenuController.changeControls, it just seems to return from changeControls.
My code:
MenuController.java:
public class MenuController extends AbstractAppState implements ScreenController{
//...
public void changeControls(String s){
ControlsButton1.setText("Press any button...");
System.out.println("changeControls in MenuController called (Action: "+Controls.Action.values()[Integer.parseInt(s)]+" )");
Controls.requestKeyChange(Controls.Action.values()[Integer.parseInt(s)], app.getInputManager(), new Runnable() {
public void run() {
ControlsButton1.setText(Controls.keyName);
}
});
}
}
Controls.java:
public class Controls implements ActionListener{
//...
public static void requestKeyChange(Action action,InputManager im, Runnable executeWhenDone){
System.out.println("requestKeyChange called (Arguments: "+action+", "+im+", "+executeWhenDone);
r = executeWhenDone;
removeControls(im);
setupKeyNames();
for(int i=0; i<keyCodes.size(); i++){
im.addMapping(keyNames.get(i), keyboard.get(i) ? new KeyTrigger(keyCodes.get(i)) : new MouseButtonTrigger(keyCodes.get(i)));
}
System.out.println(im.toString());
changingControls = true;
}
}
Console output:
//...
changeControls in MenuController called (Action: moveUp )
BUILD SUCCESSFUL (total time: 20 seconds)
Does anyone know why this happens?
-
I think you do need an instance of Controls for this to work. I've had a similar problem once, but I can't remember how it got fixed since I accidentally my harddrive.
-
This got solved in an other forum which is specialized in java and the game engine I'm using. It turns out that there was an error, but that code that is called from GUI events doesn't print the errors in the console.
Anyway, thanks for your help.
-
Ok, what game engine are you using? I'm planning on a game too and am currently messing around with JMonkeyEngine.
-
I'm using jMonkeyEngine as well. It's a very decent game engine in terms of performance. It's build-in features are a bit limited, but it's easy to extend the available ones. So if you want a good performance and don't mind having to code a lot yourself, it's a good engine for you.