在SpriteKit游戏中创建AppKit元素 [英] Creating AppKit elements in a SpriteKit game

查看:94
本文介绍了在SpriteKit游戏中创建AppKit元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题的标题确实说明了一切.我试图将AppKit元素(如按钮和其他控件)绑定到OS X SpriteKit游戏中.我的理解是AppKit元素可以放在SKScenes的顶部,但这如何工作?是否可以通过NSView处理?如何在SpriteKit中创建图层,或者这是一个单独的过程?

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?

推荐答案

所有AppKit UI元素都是NSResponder的子类,而大多数是NSView的子类

All AppKit UI elements are subclasses of NSResponder and most are subclasses of NSView

这意味着,与其他任何Cocoa应用程序一样,您具有几乎相同的响应者链.

This means like any other Cocoa app, you have very much the same responder chain.

SpriteKit添加了基于SKNode的NSResponder子类,它们都生活在SKView中.

SpriteKit adds NSResponder subclasses based on SKNode and they all live in an SKView.

在单个窗口中,所有内容都将在其响应者链中具有相同的窗口. 即使控件和视图位于单独的窗口或菜单栏中的菜单中,所有内容都共享响应者链.在某种程度上对NSApplication而言.

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.

您真正想做的就是确定最佳的用户体验.但是,NSResponder的任何子类都可以沿链转发消息. 只要该消息在链中得到处理,它就会起作用.

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.

这允许您在应用程序委托或窗口控制器甚至视图控制器中设置IBAction方法,并将这些方法选择器分配为控件的操作.响应者链和称为零目标的消息传递,是由Objective-C的特性支持的Cocoa中一些最基本,最强大的设计模式.花一些时间在响应者链上使用Apple文档.然后考虑仅具有按钮或滑块的简单应用程序.将相同的内容应用于您的游戏.

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.

这篇关于在SpriteKit游戏中创建AppKit元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆