问题描述
所以我在做一个游戏,在所说的游戏中,您将使用DPad在现场移动球.我正在使用Xcode 7 Beta 5,尽管beta 4中存在相同的问题.这是测试视图控制器的代码:
So I'm making a game and in said game, you will use a DPad to move your ball around the scene. I'm using Xcode 7 Beta 5 though the same problem existed in beta 4. Here is the code of a test view controller:
class TestController: UIViewController,DPadDelegate {
@IBOutlet var scnView:SCNView!
@IBOutlet var dpad:DPad!
var timer:NSTimer?
var update:NSTimer?
var colors = [UIColor.blueColor(),UIColor.redColor(),UIColor.whiteColor(),UIColor.yellowColor(),UIColor.cyanColor(),UIColor.orangeColor(),UIColor.magentaColor(),UIColor.purpleColor()]
var player:SCNNode!
var camera:SCNNode = SCNNode()
var i = 0
override func viewDidLoad() {
super.viewDidLoad()
NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: "ColorCubeUpdate", userInfo: nil, repeats: true)
NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "updateCamera", userInfo: nil, repeats: true)
dpad.delegate = self
player = SCNNode(geometry: SCNSphere(radius: 0.25))
player.geometry?.firstMaterial?.diffuse.contents = UIImage(named: "PlainEyes1")
player.geometry?.firstMaterial?.multiply.contents = UIColor(red: 1.0, green: 0.5, blue: 0.5, alpha: 1.0)
player.position = SCNVector3Make(0, 1.5, 0)
player.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Dynamic, shape: SCNPhysicsShape(geometry: player.geometry!, options: nil))
scnView.scene?.rootNode.addChildNode(player)
camera.camera = SCNCamera()
let constraint = SCNLookAtConstraint(target: player)
camera.constraints? = [constraint]
}
func updateCamera() {
i += 1
print(i)
print("player's position \(player.position) camera position \(camera.position)")
camera.position = player.position//SCNVector3Make(player.position.x+4, player.position.y+2, player.position.z)
}
func dPadDown() {
player.physicsBody?.applyForce(SCNVector3(x: 1, y: 0, z: 0), atPosition: SCNVector3(x: 0, y: 0, z: 0), impulse: false)
}
func dPadUp() {
player.physicsBody?.applyForce(SCNVector3(x: -1, y: 0, z: 0), atPosition: SCNVector3(x: 0, y: 0, z: 0), impulse: false)
}
func dPadLeft() {
player.physicsBody?.applyForce(SCNVector3(x: 0, y: 0, z: 1), atPosition: SCNVector3(x: 0, y: 0, z: 0), impulse: false)
}
func dPadRight() {
player.physicsBody?.applyForce(SCNVector3(x: 0, y: 0, z: -1), atPosition: SCNVector3(x: 0, y: 0, z: 0), impulse: false)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
colors数组用于其他地方,i变量仅用于调试,如您在UpdateCamera函数中看到的那样.一切看起来都不错,但是这是我在Xcode中的输出,它显示了我根本无法移动相机的问题的根源:
The colors array is used elsewhere an the i variable is just for debug as you can see in the UpdateCamera function. This all looks alright but here's my output in Xcode shows the source of a problem I'm having where the camera does not move at all:
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)50
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)50
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)51
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)51
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)52
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)52
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)53
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)53
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)54
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)54
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)55
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)55
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)56
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)56
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)57
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)57
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)58
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)58
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)59
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)59
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)60
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)60
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)61
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)61
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)62
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)62
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)63
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)63
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)64
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)64
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)65
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)65
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)66
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)66
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)67
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)67
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)68
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)68
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)69
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)69
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)70
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)70
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)71
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)71
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)72
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)72
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)73
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)73
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)74
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)74
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)75
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)75
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)76
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)76
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)77
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)77
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)78
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)78
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)79
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)79
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)80
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)80
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)81
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)81
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)82
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)82
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)83
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)83
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)84
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)84
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)85
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)85
玩家位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置SCNVector3(x:0.0,y:1.5,z:0.0)
player's position SCNVector3(x: 0.0, y: 1.5, z: 0.0) camera position SCNVector3(x: 0.0, y: 1.5, z: 0.0)
但是,在我的设备上,我看到球掉在地板上(由scn文件制成)并按预期方式工作.唯一的问题是我无法访问播放器的实际位置,因此无法移动相机.
However on my device, I see the ball fall on a floor (made in a scn file) and act as expected. The only problem is that I don't have access to the actual position of the player and thus cannot move my camera.
我尝试使用transform而不是position,但这也不起作用.请帮忙!预先感谢!
I have tried using transform instead of position and that didn't work either. Please help!Thanks in advance!
推荐答案
,您应该打印节点presentationNode
的position
.
这篇关于Xcode 7 SceneKit对象的position属性在移动时不会更新吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!