I'm building a sprite kit game and have created a UIView with collection views and buttons to represent in-game inventory. From my past experience with UIView, if I add one on top of another, the top UIView would intercept touches, unless it's user interaction enabled is set to NO.
However, when I add my inventory UIView
to Scene.view
with user interaction set to YES, it appears that sprite nodes in my scene beneath the UIView still receive touches, or at least nodes that have user interaction enabled set to YES do.
As a result, it is possible for the user to interact with my inventory UIView, and still cause actions on the game board under the inventory. It appears that Kobold-Kit based button behaviors also act randomly with ones on one side of the screen being tappable through a UIView, while others are not. My other nodes that have touchesBegan: code do ignore the UIView on top of them.
I even tried to add another node on top of the existing scene, so it would capture all touches, but this does not seem to help in this case.
I would appreciate if someone explains how to properly combine UIViews with SKScene and SKSpriteNodes if I want some of my nodes to be interactive.
- Do I need a separate scene for the inventory?
- Is there a way to disable passing of touches to the scene while inventory is active?
Here's what I have so far:
-(void)didMoveToView:(SKView *)view {
[super didMoveToView:view];
messageConsole = [[MyTextView alloc] initWithFrame:CGRectMake(playerPortraitOffset, 768-75, 415, 75)];
messageConsole.backgroundColor = [UIColor clearColor];
messageConsole.font = [UIFont boldSystemFontOfSize:10];
messageConsole.textColor = [UIColor lightGrayColor];
messageConsole.editable = NO;
[self.view addSubview:messageConsole];
[self.view addSubview:inventoryViewController.view];
}
UPDATE: Tested Kobold Kit's Behavior with following results:
- For Top level UI elements, like Label, collection View and UIButton, they do not pass touches through
- For regular UIViews and UIImageViews, they pass touches to the scene EVEN IF there is an interactive UIButton beneath them. Removing UIImage and exposing the same UIButton seems to stop touches from passing through.