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

查看:29
本文介绍了在 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 方法,并将这些方法选择器分配为控件的操作.响应者链和所谓的无目标消息传递是 Cocoa 中由 Objective-C 的特性支持的一些最基本和最强大的设计模式.花一些时间查看响应者链上的 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天全站免登陆