문제

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top