Search code examples
iosobjective-cuikitsprite-kitskscene

Adding a UIButton to a SKScene


What is the best way to add a UIButton to an SKScene?

I realize that I probably can't add it as a subview of the scene, so what is the alternative so that I can have a tappable button on top of a scene?


Solution

  • You can opt for one of the following ways:

    1 - Subclass SKSpriteNode to act as a button

    2 - Implement touch delegates within the scene and respond if your 'button' node is touched

    This link will tell u how to implement the two above.

    3 - Use a component like the SpriteKit Button which can be found here.