iOS 7 SpriteKit - Creating game menus/buttons (Scenes vs. more view controllers)

前端 未结 3 684
暗喜
暗喜 2021-02-03 10:06

So, I\'ve begun working on a project in SpriteKit, and I\'m hoping to be able to implement a \"main menu\" scene with a few buttons. One would go to a level select screen, one w

3条回答
  •  别跟我提以往
    2021-02-03 10:32

    I encountered this problem a few month ago when I started building my game with spriteKit.

    And my answer is not really definite but here is my advice: For the in-game I would set up the UI programmatically - seems like a lot of work but for a video game it is actually not that bad. But some menu could be in a storyboard setup or xib file - like the main menu, and the different submenu outside the game.

    For the touch add that function to your scene.m

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
    {
    
        CGPoint location = [[touches anyObject] locationInNode:self];
    }
    

    And then you can use CGRectContainsPoint();

    Or you can add a UITapGestureRecognizer to you view controller.

    UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    
    recognizer.delegate = self;
    
    [view addGestureRecognizer:recognizer];
    

    Setting up buttons in SKScene

提交回复
热议问题