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?
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?
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.
/// create a uibutton in skscene (spritkit)
UIButton * startButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 60, 20)];
startButton.backgroundColor = [UIColor redColor];
[self.view addSubview:startButton];
/// if u want to connect it to a method or function ///
[startButton addTarget:self action:@selector(StartBtn) forControlEvents:UIControlEventTouchUpInside];