问题
The title of the question really says it all. I am trying to tie in AppKit elements like buttons and other controls into a OS X SpriteKit game. My understanding is that AppKit elements can be placed on top of SKScenes, but how does this work? Would this be handled via an NSView? How does the layer get created in SpriteKit or is this a separate process altogether?
回答1:
All AppKit UI elements are subclasses of NSResponder and most are subclasses of NSView
This means like any other Cocoa app, you have very much the same responder chain.
SpriteKit adds NSResponder subclasses based on SKNode and they all live in an SKView.
Together in a single window everything will have the same window in their responder chain. Even if controls and views are in a separate window or menus in the menu bar, everything shares the responder chain. At some level to NSApplication.
What you really want to do is determine the best user experience. But any subclass of NSResponder can forward messages up the chain. As long as that message is handled in the chain, it will work.
This allows you to set up IBAction methods in your app delegate or window controller or even a view controller and assign those method selectors as the actions of controls. The responder chain and something called nil-targeted messaging are some of the most fundamental and powerful design patterns in Cocoa enabled by the nature of Objective-C. Spend some time with the Apple docs on the responder chain. Then think about simple apps with a button or slider only. Apply the same to your game.
来源:https://stackoverflow.com/questions/27658589/creating-appkit-elements-in-a-spritekit-game