This site requires JavaScript, please enable it in your browser!
Greenfoot back
Zamoht
Zamoht wrote ...

2013/9/3

Razer controller and Greenfoot

Zamoht Zamoht

2013/9/3

#
I have the Razer Onza and I would like to create a scenario reacting to the controller input. My problem is that the controller doesn't seem to have any "keyboard like" input so I can't use Greenfoot.isKeyDown(string); or Greenfoot.getKey(); . Is what I'm trying to even possible and if it is what would a solution look like?
Gevater_Tod4711 Gevater_Tod4711

2013/9/3

#
I think the solution of this problem is possible but not easy. Greenfoot.isKeyDown will not work for your controller but if the controller fires KeyEvents (or similarly events) it is possible to react on this events. Unfortunatly I don't know what kind of events are used by controllers or even if any events are fired by the controller (but at least I assume it has events). If you know the events that are used and react on this events it's possible to handle them (almost like Greenfoot.isKeyDown()). But you need to know which events are used. Therefore you should search the internet or the APIs and try to get some events from your controller.
Gevater_Tod4711 Gevater_Tod4711

2013/9/3

#
You should also have a look at this. I'm not shure if this APIs can already be used but it looks like that is what you need.
Zamoht Zamoht

2013/9/3

#
I will look at it and tell you what I find out.
Zamoht Zamoht

2013/9/3

#
I wrote this simple code with the GamePad class:
public class PadWorld extends World
{
    GamePad myPad;
    /**
     * Constructor for objects of class PadWorld.
     * 
     */
    public PadWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        myPad = GamePad.getGamePad();
    }
}
The problem is that I get a ton of errors:
java.lang.IllegalArgumentException: Given klassFile must be a file
	at GamePad.loadLib(GamePad.java:55)
	at GamePad.<clinit>(GamePad.java:128)
	at PadWorld.<init>(PadWorld.java:20)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at greenfoot.core.Simulation.newInstance(Simulation.java:578)
	at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:408)
	at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:465)
	at greenfoot.core.Simulation.maybePause(Simulation.java:279)
	at greenfoot.core.Simulation.runContent(Simulation.java:210)
	at greenfoot.core.Simulation.run(Simulation.java:203)
java.lang.NoClassDefFoundError: net/java/games/input/ControllerEnvironment
	at gamepadlib.GamePadLoader.getGamePads(GamePadLoader.java:110)
	at GamePad.refreshGamePads(GamePad.java:363)
	at GamePad.getGamePads(GamePad.java:334)
	at GamePad.getGamePad(GamePad.java:302)
	at GamePad.getGamePad(GamePad.java:288)
	at PadWorld.<init>(PadWorld.java:20)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at greenfoot.core.Simulation.newInstance(Simulation.java:578)
	at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:408)
	at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:465)
	at greenfoot.core.Simulation.maybePause(Simulation.java:279)
	at greenfoot.core.Simulation.runContent(Simulation.java:210)
	at greenfoot.core.Simulation.run(Simulation.java:203)
Caused by: java.lang.ClassNotFoundException: net.java.games.input.ControllerEnvironment
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
	... 16 more
I guess this could be due to new versions of Greenfoot and/or Java?
Gevater_Tod4711 Gevater_Tod4711

2013/9/3

#
The stack trace sais that the library couldn't be loaded. I think that can either be because you didn't place the library at the right place or didn't include it right or there is a bug in the library itselves or a Greenfoot bug. You should try to readd the library to the scenario like it's tould in the discription. If this doesn't work you probably need help from the Greenfoot team.
Zamoht Zamoht

2013/9/3

#
Okay so on my Mac with Greenfoot 2.2.1 i got the errors above. Now I'm home on my PC with Greenfoot 2.3.0 and I get this popup when I open the project: An error occurred in a file for which the source cannot be found. class: source line number: C:\Users\Thomas\Desktop\GamePadTemplate\gamepadlib\GamePadLoader.java:4 package net.java.games.input does not exist Again my question is if this could be due to new versions of Greenfoot and/or Java? With this new error I think the net.java.games.input.* is renamed or doesn't exist in the newer versions of Java. By looking at some of the code I know for sure that I'm not going to code this myself. I guess I will have to hope for an update or I will have to give up for now.
Gevater_Tod4711 Gevater_Tod4711

2013/9/3

#
I think this problem is not because of your Greenfoot version but because the library for the GamePad support is buggy. May the greenfoot team can have a look at this. But I think without access to the code of the library you can't handle this problem.
davmac davmac

2013/9/3

#
I've updated the template, could you give it a try now?
davmac davmac

2013/9/3

#
(it may need Greenfoot 2.3.0 now).
Zamoht Zamoht

2013/9/3

#
Okay the problem was that I used the default Windows 7 "unzipper" (I think). I downloaded winrar and now it works or well it comes with the error "No gamepad found, are you sure it's plugged in?" since I haven't the controller nearby right now. Sorry for the trouble :( I will come back when I know if I can connect the controller. And not that it seems to be an issue but I get a warning in the Terminal Window: WARNING: Found unknown Windows version: Windows 7 Attempting to use default windows plug-in. Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin Thanks for the help.
You need to login to post a reply.