向Scene Kit(Swift)添加自定义游戏逻辑 [英] Adding custom game logic to Scene Kit (Swift)

查看:140
本文介绍了向Scene Kit(Swift)添加自定义游戏逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我的GameViewController添加一个游戏循环(来自Swift游戏模板,用于iOS开发),以便创建一个应用程序并找到这个参考页面,解释如何执行此操作:

I need to add a game loop to my GameViewController (From the Swift "Game" template for iOS development) in order to create an application and found this reference page explaining how to do this:

https://developer.apple .com / library / prerelease / ios / documentation / SceneKit / Reference / SCNSceneRendererDelegate_Protocol /

然而,当我尝试将SCNView的委托设置为ViewController它会抛出警告和错误(在viewDidLoad()内部):

However when I try to set the delegate of the SCNView to be the ViewController it throws up warnings and errors (inside viewDidLoad()):

gameView.delegate = self

其中gameView连接到我的故事板中的SCNView:

Where gameView is connected to an SCNView in my storyboard:

@IBOutlet weak var gameView: SCNView!

如果有人可以链接使用Swift和Scene Kit设置游戏逻辑的代码示例,那将是很棒的或者从头开始向我解释。谢谢!

It would be brilliant if someone could link a code example of setting up game logic using Swift and Scene Kit or explain it to me from the ground up. Thank you!

推荐答案

当你指定:

gameView.delegate = self

这需要 self 是一个声明符合 SCNSceneRendererDelegate 协议的类。要使您的视图控制器类声明协议一致性,请使用描述的语法

This requires that self be a class that declares conformance to the SCNSceneRendererDelegate protocol. To make your view controller class declare protocol conformance, use the syntax described in the Swift book:

class ViewController: UIViewController, SCNSceneRendererDelegate  {
    //                ~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~~~~ ^
    //                ^- superclass     ^- protocol              |
    //                   more protocols if you conform to them --/ 

    // ... rest of class definition ...
}

这篇关于向Scene Kit(Swift)添加自定义游戏逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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