The Virtual controllers appear but are then obscured by objects added to the view. I've also tried adding the virtual controllers in the UIViewController but this doesn't work either.
Is it possible to use GCVirtualController directly with SKScene?
class GameScene: SKScene {
private var _virtualController: Any?
public var virtualController: GCVirtualController? {
get { return self._virtualController as? GCVirtualController }
set { self._virtualController = newValue }
}
override func didMove(to view: SKView) {
let background = SKSpriteNode(imageNamed: ".jpg")
background.zPosition = -1
addChild(background)
let virtualConfig = GCVirtualController.Configuration()
virtualConfig.elements = [GCInputLeftThumbstick, GCInputRightThumbstick, GCInputButtonA, GCInputButtonB]
virtualController = GCVirtualController(configuration: virtualConfig)
virtualController?.connect()
}
}
It appears the issue only occurs when pushing from one ViewController to the GameViewController.
When launching to the GameViewController the issue does not occur.
The Virtual Game Controller can run on any view controller running iOS 15 At least but for the purpose of work it is best viewed in landscape but you need to complete the codes as a physical gamepad.
For the virtual game controller to appear you need to register a physical game controller and apply the functions of notification when connect and disconnect a controller as you do with physical controller exactly.
Here is a code to setup and register a virtual and physical game controller I use and it works for me.
1st you need to import the Game Controller Library
Then you define the Virtual Controller Under your Controller Class
And then you call the setupGameController Function In Your ViewDidLoad()
and here is the main function to setup your Virtual and physical game controller
Then to act with the virtual or physical gamepad actions you need to assign the connect and register for the game controller as
And Here Is A Result of the code on a very basic ship sample of Xcode