| Modifier and Type | Field and Description |
|---|---|
| private final Configuration | |
| private ControllerIndex[] | |
| private boolean | |
| private String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | ControllerManager(Configuration
see configuration, String and its fieldsThe path to a file containing SDL controller mappings. mappingsPath)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addMappingsFromFile(String
The path to the file containing controller mappings. path)This method adds mappings held in the specified file. |
| public boolean | Returns: Whether or not vibration was successfully startedThe index of the controller that will be vibrated index, float The intensity of the left rumble motor (0-1) leftMagnitude, float The intensity of the rught rumble motor (0-1) rightMagnitude, int duration_ms)Starts vibrating the controller at this given index. |
| public ControllerIndex | Returns: The internal ControllerIndex object for the passed index.the index of the ControllerIndex that will be returned index)Returns a the ControllerIndex object with the passed index (0 for p1, 1 for p2, etc.). |
| public native String | Returns: last error message logged by the native lib. Use this for debugging purposes.
|
| public int | Returns: the number of connected controllers.Return the number of controllers that are actually connected. |
| public ControllerState | Returns: The state of the controller at the passed index.The index of the controller to be checked index)Return the state of a controller at the passed index. |
| public void | |
| private native boolean | |
| private native boolean | |
| private native void | |
| private native boolean | |
| private native int | |
| private native boolean | |
| public void | |
| public boolean | Returns: True if the controller list was refreshed, false otherwiseRefresh the connected controllers in the controller list if something has been connected or unplugged. |
| private boolean |
| configuration | back to summary |
|---|---|
| private final Configuration configuration | |
| controllers | back to summary |
|---|---|
| private ControllerIndex[] controllers | |
| isInitialized | back to summary |
|---|---|
| private boolean isInitialized | |
| mappingsPath | back to summary |
|---|---|
| private String mappingsPath | |
| ControllerManager | back to summary |
|---|---|
| public ControllerManager() Default constructor. Makes a manager for 4 controllers with the built in mappings from here: https://github.com/gabomdq/SDL_GameControllerDB | |
| ControllerManager | back to summary |
|---|---|
| public ControllerManager(Configuration configuration) Constructor. Uses built-in mappings from here: https://github.com/gabomdq/SDL_GameControllerDB
| |
| ControllerManager | back to summary |
|---|---|
| public ControllerManager(Configuration configuration, String mappingsPath) Constructor.
| |
| addMappingsFromFile | back to summary |
|---|---|
| public void addMappingsFromFile(String path) throws IOException, IllegalStateException This method adds mappings held in the specified file. The file is copied to the temp folder so that it can be read by the native code (if running from a .jar for instance)
| |
| doVibration | back to summary |
|---|---|
| public boolean doVibration(int index, float leftMagnitude, float rightMagnitude, int duration_ms) throws IllegalStateException Starts vibrating the controller at this given index. If this fails for one reason or another (e.g. the controller at that index doesn't support haptics, or if there is no controller at that index), this method will return false. Each call to this function cancels any previous rumble effect, and calling it with 0 intensity stops any rumbling.
| |
| getControllerIndex | back to summary |
|---|---|
| public ControllerIndex getControllerIndex(int index) Returns a the ControllerIndex object with the passed index (0 for p1, 1 for p2, etc.). You should only use this method if you're worried about the object allocations from getState(). If you decide to do things this way, your code will be a good bit more verbose and you'll need to deal with potential exceptions. It is generally safe to store objects returned from this method. They will only change internally if you call quitSDLGamepad() followed by a call to initSDLGamepad(). Calling update() will run through all the controllers to check for newly plugged in or unplugged controllers. You could do this from your code, but keep that in mind.
| |
| getLastNativeError | back to summary |
|---|---|
public native String getLastNativeError()
| |
| getNumControllers | back to summary |
|---|---|
| public int getNumControllers() Return the number of controllers that are actually connected. This may disagree with the ControllerIndex objects held in here if something has been plugged in or unplugged since update() was last called.
| |
| getState | back to summary |
|---|---|
| public ControllerState getState(int index) throws IllegalStateException Return the state of a controller at the passed index. This is probably the way most people should use this library. It's simpler and less verbose, and controller connections and disconnections are automatically handled. Also, no exceptions are thrown here (unless Jamepad isn't initialized), so you don't need to have a million try/catches or anything. The returned state is immutable. This means an object is allocated every time you call this (unless the controller is disconnected). This shouldn't be a big deal (even for games) if your GC is tuned well, but if this is a problem for you, you can go directly through the internal ControllerIndex objects using getControllerIndex(). update() is called each time this method is called. Buttons are also queried, so values returned from isButtonJustPressed() in ControllerIndex may not be what you expect. Calling this method will have side effects if you are using the ControllerIndex objects yourself. This should be fine unless you are mixing and matching this method with ControllerIndex objects, which you probably shouldn't do anyway.
| |
| initSDLGamepad | back to summary |
|---|---|
| public void initSDLGamepad() throws IllegalStateException Initialize the ControllerIndex library. This loads the native library and initializes SDL in the native code.
| |
| nativeAddMappingsFromBuffer | back to summary |
|---|---|
| private native boolean nativeAddMappingsFromBuffer(byte[] buffer, int length) | |
| nativeAddMappingsFromFile | back to summary |
|---|---|
| private native boolean nativeAddMappingsFromFile(String path) | |
| nativeCloseSDLGamepad | back to summary |
|---|---|
| private native void nativeCloseSDLGamepad() | |
| nativeControllerConnectedOrDisconnected | back to summary |
|---|---|
| private native boolean nativeControllerConnectedOrDisconnected() | |
| nativeGetNumRollers | back to summary |
|---|---|
| private native int nativeGetNumRollers() | |
| nativeInitSDLGamepad | back to summary |
|---|---|
| private native boolean nativeInitSDLGamepad(boolean disableRawInput) | |
| quitSDLGamepad | back to summary |
|---|---|
| public void quitSDLGamepad() This method quits all the native stuff. Call it when you're done with Jamepad. | |
| update | back to summary |
|---|---|
| public boolean update() Refresh the connected controllers in the controller list if something has been connected or unplugged. If there hasn't been a change in whether controller are connected or not, nothing will happen.
| |
| verifyInitialized | back to summary |
|---|---|
| private boolean verifyInitialized() throws IllegalStateException | |