# GameController button B and menu

**URL:** <https://forums.kodeco.com/t/gamecontroller-button-b-and-menu/84984>\
**Category:** 2D iOS & tvOS Games by Tutorials\
**Created:** [October 14, 2019, 6:56pm UTC](https://forums.kodeco.com/t/gamecontroller-button-b-and-menu/84984 "2019-10-14T18:56:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan-willem](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jan-willem/32/81494_2.png) [@jan-willem](https://forums.kodeco.com/u/jan-willem)\
**Post date:** [October 14, 2019, 6:56pm UTC](https://forums.kodeco.com/t/gamecontroller-button-b-and-menu/84984/1 "2019-10-14T18:56:17Z")

</div>

Using XCode and SpriteKit and connecting and using the extendedGamePad.

There seems to be the problem that when ever i use the B of Menu button, my program stops and tvOS returns to it’s menu.

So the menu button will be great to pause the game, and the B button to “jump” or “activate item”, but i can’t use these buttons right now, all the other buttons and thrumbstick are working fine.

Anybody who knows why this happens ? The ‘print(button)’ is called before the returning to the menu.  
(see code below)

JW Sipkes

```
enum ExtendedGamePadButton {
    case A, B, X, Y, menu
}

func behandelenExtendedGamePadButtons(button: ExtendedGamePadButton) {
    print(button)
}

func behandelenExtendedGamePad(controller: GCController) {
    controller.extendedGamepad?.valueChangedHandler = {
        (gamepad: GCExtendedGamepad, element: GCControllerElement) in
    
       if gamepad.buttonA.isPressed {
            self.behandelenExtendedGamePadButtons(button: ExtendedGamePadButton.A)
        }
        if gamepad.buttonB.isPressed {
            self.behandelenExtendedGamePadButtons(button: ExtendedGamePadButton.B)
        }
        if gamepad.buttonX.isPressed {
            self.behandelenExtendedGamePadButtons(button: ExtendedGamePadButton.X)
        }
        if gamepad.buttonY.isPressed {
            self.behandelenExtendedGamePadButtons(button: ExtendedGamePadButton.Y)
        }
        if gamepad.buttonMenu.isPressed {
            self.behandelenExtendedGamePadButtons(button: ExtendedGamePadButton.menu)
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![wizfinger](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/wizfinger/32/110937_2.png) [@wizfinger](https://forums.kodeco.com/u/wizfinger)\
**Post date:** [October 26, 2019, 11:24am UTC](https://forums.kodeco.com/t/gamecontroller-button-b-and-menu/84984/2 "2019-10-26T11:24:34Z")

</div>

On tvOS, to make the B-button normal again, make sure the viewcontroller that controls your SKView is of class GCEventViewController and not UIViewController. Then set the controllerUserInteractionEnabled property to NO. This will make sure you can catch the B-button, menu and select.

Please note that the buttonMenu is only available on iOS 13 / tvOS 13, and I can only get it working on a real device, not in the simulator.

---

<div class="post-metadata">

**Author:** ![jan-willem](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jan-willem/32/81494_2.png) [@jan-willem](https://forums.kodeco.com/u/jan-willem)\
**Post date:** [October 26, 2019, 8:12pm UTC](https://forums.kodeco.com/t/gamecontroller-button-b-and-menu/84984/3 "2019-10-26T20:12:02Z")

</div>

O yes, thanks ! This solves the problem.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [March 29, 2020, 10:56am UTC](https://forums.kodeco.com/t/gamecontroller-button-b-and-menu/84984/4 "2020-03-29T10:56:17Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
