On-screen joystick(s) for iOS and iPadOS using Metal?

Hey all. I took a look at a video that caught my attention(https://developer.apple.com/videos/play/wwdc2021/10081) and wish to use this for my ios and iPad game. However, the language used here is swift, and want to use either objective-c or c++. Did anyone here used this method shown is this video but without swift?

Replies

Hi CuriousAsking123

The GCVirtualController class is available from Objective-C. Here is a code snippet showing how to set it up.

#import <GameController/GameController.h>

// Assumes your class declares an instance variable named '_virtualController' with type GCVirtualController*

        GCVirtualControllerConfiguration *configuration = [GCVirtualControllerConfiguration new];
        configuration.elements = [NSSet setWithArray:@[
            GCInputButtonA,
            GCInputButtonB,
            GCInputButtonX,
            GCInputButtonY,
            GCInputLeftShoulder,
            GCInputLeftTrigger,
            GCInputRightShoulder,
            GCInputRightTrigger,
            GCInputDirectionPad,
            GCInputRightThumbstick
        ]];
        
        _virtualController = [GCVirtualController virtualControllerWithConfiguration:configuration];
        [_virtualController connectWithReplyHandler:^(NSError *error) {
            if (error) { NSLog(@"%@", error); }
        }];
  • Is this objective-c? That's my target language for the virtual joystick

  • Yes, that is Objective-C code.

  • OK cool so I use this shown here and the virtual joystick will pop-up on the screen without me having to add any more code?

Add a Comment