Class GCController

  • All Implemented Interfaces:
    GCDevice, NSObject

    public class GCController
    extends NSObject
    implements GCDevice
    Controllers are available to an application that links to GameController.framework. There are 2 ways to access controllers paired to the system, adopt both to ensure the best user experience: 1: Querying for the the current array or controllers using [GCController controllers]. 2: Registering for Connection/Disconnection notifications from NSNotificationCenter. Only controllers that support one of the allowed profiles, such as GCExtendedGamepad, will be enumerated. Check for the profile supported before using a controller in your application. Ignore a controller that doesn't support a profile that suits your application, as the user will expect their controller to either be fully supported or not supported at all. API-Since: 7.0
    • Constructor Detail

      • GCController

        protected GCController​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static GCController allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(@NotNull
                                                                   @NotNull java.lang.String key)
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(@NotNull
                                                                   @NotNull java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(@NotNull
                                                                                 @NotNull java.lang.Object aTarget,
                                                                                 @NotNull
                                                                                 @NotNull org.moe.natj.objc.SEL aSelector,
                                                                                 @Nullable
                                                                                 @Nullable java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        @NotNull
        public static @NotNull NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        @NotNull
        public static @NotNull org.moe.natj.objc.Class classForKeyedUnarchiver()
      • controllers

        @NotNull
        public static @NotNull NSArray<? extends GCController> controllers()
        Get a list of controllers currently attached to the system.
        See Also:
        GCControllerDidConnectNotification, GCControllerDidDisconnectNotification
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        @NotNull
        public static @NotNull NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(@NotNull
                                                                                             @NotNull java.lang.String key)
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • startWirelessControllerDiscoveryWithCompletionHandler

        public static void startWirelessControllerDiscoveryWithCompletionHandler​(@Nullable
                                                                                 @Nullable GCController.Block_startWirelessControllerDiscoveryWithCompletionHandler completionHandler)
        Start discovery of new wireless controllers that are discoverable. This is an asynchronous and the supplied completionHandler will get called once no more devices can be found. If there are already multiple controllers available for use, there may be little reason to automatically start discovery of new wireless controllers. In this situation it may be best to allow the user to start discovery manually via in-game UI. Once discovery has started new controllers will notify themselves as connected via GCControllerDidConnectNotification. As the notification arrives the controller is also available in the controllers array. The completionHandler could be used to update UI and/or game state to indicate that no more controllers will be found and the current set of controllers is what is available for use in the game. If a completionHandler was provided, it will be called once when discovery stops. Either from an explicit call to stopWirelessControllerDiscovery or from timing out or stopping in its natural course of operation. Thus the completionHandler will at most be called once per call to startWirelessControllerDiscoveryWithCompletionHandler:. The completionHandler may also not get called at all, if for example startWirelessControllerDiscoveryWithCompletionHandler: is called multiple times during dicovery. For this case the net effect is that the completionHandler is replaced with each call and only the last one set before discovery stops will be called.
        Parameters:
        completionHandler - an optional handler that is called when discovery stops. (may be nil, in which case you will not be notified when discovery stops)
        See Also:
        stopWirelessControllerDiscovery(), controllers()
      • stopWirelessControllerDiscovery

        public static void stopWirelessControllerDiscovery()
        If no more controllers are needed, depending on game state or number of controllers supported by a game, the discovery process can be stopped. Calling stopWirelessControllerDiscovery when no discovery is currently in progress will return immediately without any effect, thus it is safe to call even if the completionHandler of startWirelessControllerDiscoveryWithCompletionHandler: has been called.
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • gamepad

        @Nullable
        @Deprecated
        public @Nullable GCGamepad gamepad()
        Deprecated.
        Gets the profile for the controller that suits current application. There are several supported profiles, with an additional optional profile for motion as well. Each controller may be able to map its inputs into all profiles or just one kind of profile. Query for the controller profile that suits your game, the simplest kind will be supported by the broadest variety of controllers. A controller supporting the Extended Gamepad profile for example supports the Gamepad profile and more. As such it can always be used just in the Gamepad profile if that suits the game. A physical controller that supports a profile must support it completely. That means that all buttons and axis inputs must be valid inputs that a developer can utilize. If a controller does not support the given profile the returned value will be nil. Use this to filter controllers if the application requires a specific kind of profile.
        See Also:
        API-Since: 7.0 Deprecated-Since: 10.0
      • handlerQueue

        @NotNull
        public @NotNull dispatch_queue_t handlerQueue()
        Description copied from interface: GCDevice
        The dispatch queue that element value change handlers are submitted on. The default queue is main, and setting this to any other queue will make value change handlers dispatch async on the given queue. This is useful if the main game loop of the application is not on main, or if input logic is handled on another thread from the main game loop.
        Specified by:
        handlerQueue in interface GCDevice
        See Also:
        GCControllerAxisInput.valueChangedHandler, GCControllerButtonInput.valueChangedHandler, GCControllerButtonInput.pressedChangedHandler, GCControllerDirectionPad.valueChangedHandler, API-Since: 7.0
      • isAttachedToDevice

        public boolean isAttachedToDevice()
        A controller may be form fitting or otherwise closely attached to the device. This closeness to other inputs on the device may suggest that interaction with the device may use other inputs easily. This is presented to developers to allow them to make informed decisions about UI and interactions to choose for their game in this situation.
      • microGamepad

        @Nullable
        public @Nullable GCMicroGamepad microGamepad()
      • motion

        @Nullable
        public @Nullable GCMotion motion()
        Gets the motion input profile. This profile is optional and may be available if the controller is attached to a device that supports motion. If this is nil the controller does not support motion input and only the gamepad & extendedGamepad profiles are available.
        See Also:
        gamepad(), API-Since: 8.0
      • playerIndex

        public long playerIndex()
        A player index for the controller, defaults to GCControllerPlayerIndexUnset. This can be set both for the application to keep track of controllers and as a signal to make a controller display a player index on a set of LEDs or some other mechanism. A controller is not guaranteed to have a visual display of the playerIndex, playerIndex does not persist for a controller with regards to a system. Negative values less than GCControllerPlayerIndexUnset will just map back to GCControllerPlayerIndexUnset when read back.
      • setHandlerQueue

        public void setHandlerQueue​(@NotNull
                                    @NotNull dispatch_queue_t value)
        Description copied from interface: GCDevice
        The dispatch queue that element value change handlers are submitted on. The default queue is main, and setting this to any other queue will make value change handlers dispatch async on the given queue. This is useful if the main game loop of the application is not on main, or if input logic is handled on another thread from the main game loop.
        Specified by:
        setHandlerQueue in interface GCDevice
        See Also:
        GCControllerAxisInput.valueChangedHandler, GCControllerButtonInput.valueChangedHandler, GCControllerButtonInput.pressedChangedHandler, GCControllerDirectionPad.valueChangedHandler, API-Since: 7.0
      • setPlayerIndex

        public void setPlayerIndex​(long value)
        A player index for the controller, defaults to GCControllerPlayerIndexUnset. This can be set both for the application to keep track of controllers and as a signal to make a controller display a player index on a set of LEDs or some other mechanism. A controller is not guaranteed to have a visual display of the playerIndex, playerIndex does not persist for a controller with regards to a system. Negative values less than GCControllerPlayerIndexUnset will just map back to GCControllerPlayerIndexUnset when read back.
      • vendorName

        @Nullable
        public @Nullable java.lang.String vendorName()
        Description copied from interface: GCDevice
        A vendor supplied name. May be nil, and is not guaranteed to be unique. This should not be used as a key in a dictionary, but simply as a way to present some basic information about the device in testing or to the user. API-Since: 7.0
        Specified by:
        vendorName in interface GCDevice
      • capture

        @NotNull
        public @NotNull GCController capture()
        Polls the state vector of the controller and saves it to a new and writable instance of GCController. If your application is heavily multithreaded this may also be useful to guarantee atomicity of input handling as a snapshot will not change based on user input once it is taken.
        Returns:
        A new controller with the duplicated state vector of the current controller API-Since: 13.0
        See Also:
        snapshot
      • controllerWithExtendedGamepad

        @NotNull
        public static @NotNull GCController controllerWithExtendedGamepad()
        Creates a controller with an extended gamepad profile. This controller will be considered a snapshot, allowing developers to write to any GCControllerElement of its profiles.
        Returns:
        A new controller with an extended gamepad profile API-Since: 13.0
        See Also:
        snapshot
      • controllerWithMicroGamepad

        @NotNull
        public static @NotNull GCController controllerWithMicroGamepad()
        Creates a controller with a micro gamepad profile. This controller will be considered a snapshot, allowing developers to write to any GCControllerElement of its profiles.
        Returns:
        A new controller with a micro gamepad profile API-Since: 13.0
        See Also:
        snapshot
      • isSnapshot

        public boolean isSnapshot()
        A controller may represent a real device managed by the operating system, or a virtual snapshot created by the developer. If a controller is directly created by the developer, it is considered to be a snapshot, allowing direct writes to any GCControllerElement of its profiles. If the controller is not snapshot, the system will reject any write requests to GCControllerElement.
        See Also:
        controllerWithMicroGamepad(), controllerWithExtendedGamepad(), API-Since: 13.0
      • productCategory

        @NotNull
        public @NotNull java.lang.String productCategory()
        Description copied from interface: GCDevice
        The product category the device belongs to. This is useful for setting appropriate UI elements based on what type of device is connected.
        Specified by:
        productCategory in interface GCDevice
        See Also:
        API-Since: 13.0
      • battery

        @Nullable
        public @Nullable GCDeviceBattery battery()
        Gets the battery information if controller supports one This property is useful when you try to notify your user to change or charge controller before it runs out of battery life or simply display the current battery level and status. API-Since: 14.0
      • current

        @Nullable
        public static @Nullable GCController current()
        The most recently used game controller. If a user actuates a game controller input, that controller will become the current one. [@note] This is useful for single player games where you only care about whether an input is pressed, and not where it came from. You will still need to register for changes to GCController.current so that your UI can remain up-to-date with the current controller. API-Since: 14.0
      • haptics

        @Nullable
        public @Nullable GCDeviceHaptics haptics()
        Gets the haptics for the controller, if one exists. Use this property to create CHHapticEngine instances according to your needs. [@note] Haptics are a drain on the controller's battery, and can be distracting when used excessively. API-Since: 14.0
      • light

        @Nullable
        public @Nullable GCDeviceLight light()
        Gets the light for the controller, if one exists. A controller's light can be used to signal information to the player, such as using different light colors based on the player index. It can also be used to react to in-game events and enhance user immersion. API-Since: 14.0
      • physicalInputProfile

        @NotNull
        public @NotNull GCPhysicalInputProfile physicalInputProfile()
        Description copied from interface: GCDevice
        Gets the physical input profile for the device. [@note] This is equivalent to the controller's gamepad, microGamepad, or extendedGamepad instance.
        Specified by:
        physicalInputProfile in interface GCDevice
        See Also:
        GCController.microGamepad, API-Since: 14.0 Deprecated-Since: 16.0 Deprecated-Message: Use the physicalInputProfile property on GCController instead. For GCKeyboard, use the keyboardInput property. For GCMouse, use the mouseInput property.
      • setShouldMonitorBackgroundEvents

        public static void setShouldMonitorBackgroundEvents​(boolean value)
        Whether the current application should monitor and respond to game controller events when it is not the frontmost application. [@example] If shouldMonitorBackgroundEvents is NO, and the application is not the frontmost application, any inputs from a game controller will not be forwarded to the application. Once the application becomes the frontmost application, game controller events will be forwarded. [@note] Starting with macOS Big Sur 11.3, shouldMonitorBackgroundEvents will be NO by default. For applications built prior to macOS Big Sur 11.3, (or running on devices with an earlier version of macOS), shouldMonitorBackgroundEvents will be YES by default. On iOS and tvOS, this property is ignored. API-Since: 14.5
      • shouldMonitorBackgroundEvents

        public static boolean shouldMonitorBackgroundEvents()
        Whether the current application should monitor and respond to game controller events when it is not the frontmost application. [@example] If shouldMonitorBackgroundEvents is NO, and the application is not the frontmost application, any inputs from a game controller will not be forwarded to the application. Once the application becomes the frontmost application, game controller events will be forwarded. [@note] Starting with macOS Big Sur 11.3, shouldMonitorBackgroundEvents will be NO by default. For applications built prior to macOS Big Sur 11.3, (or running on devices with an earlier version of macOS), shouldMonitorBackgroundEvents will be YES by default. On iOS and tvOS, this property is ignored. API-Since: 14.5
      • input

        @NotNull
        public @NotNull GCControllerLiveInput input()
        Gets the input profile for the controller. API-Since: 17.0
      • useStoredAccessor

        @Deprecated
        public static boolean useStoredAccessor()
        Deprecated.