经由过程以上办法,就可以在游戏中生成方块。那么,这个办法何时调用呢?
第一个是在开端游戏时。我们经由过程点击的方法,决定在哪里开端游戏。
这里我们 override 了 touchesBegan(_:_:) 这个办法(其实还有 touchesEnd(_:_:) ),具体为什么会在后文解释。
- override func touchesBegan(_ touches: Set, with event: UIEvent?) {
- ...
- // 添加瓶子
- func addConeNode() {
- bottleNode.position = SCNVector3(boxNodes.last!.position.x,
- boxNodes.last!.position.y + Float(kBoxWidth) * 0.75,
- boxNodes.last!.position.z)
- sceneView.scene.rootNode.addChildNode(bottleNode)
- }
- // 点击测试,有没有获得一个特点点的三维坐标?
- func anyPositionFrom(location: CGPoint) -> (SCNVector3)? {
- let results = sceneView.hitTest(location, types: .featurePoint)
- guard !results.isEmpty else {
- return nil
- }
- return SCNVector3.positionFromTransform(results[0].worldTransform)
推荐阅读
还在用浏览器内的「保存密码」功能?你的密码可能被黑客记下来了
【限时免费】岁尾最强一次云计算大年夜会,看传统、社区、互联网企业若何碰撞?安然研究人员发明,营销公司已经开端应用浏览器内置暗码治理器中已存在 11 年的一个马脚,来偷偷盗取你的电子邮件地址,>>>详细阅读
本文标题:用ARKit做一个仿微信"跳一跳"游戏
地址:http://www.17bianji.com/lsqh/40272.html
1/2 1