在SpriteKit游戏中创建AppKit元素

编程入门 行业动态 更新时间:2024-10-27 17:18:34
本文介绍了在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元素

本文发布于:2023-07-15 02:02:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1108378.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   游戏中   SpriteKit   AppKit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!