Ner*_*pps 0 xcode camera scenekit scnnode xcode7-beta5
所以我正在制作游戏,在游戏中,你将使用DPad在场景中移动你的球.虽然beta 4中存在同样的问题,但我正在使用Xcode 7 Beta 5.这是测试视图控制器的代码:
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()
}
}
Run Code Online (Sandbox Code Playgroud)
colors数组在别处使用,i变量仅用于调试,您可以在UpdateCamera函数中看到.这一切看起来都不错但是这里我在Xcode中的输出显示了我在相机根本不移动的问题的根源:
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
播放器的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
播放器的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
播放器的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置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
播放器的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置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
播放器的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
播放器的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置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
播放器的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像机位置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
玩家的位置SCNVector3(x:0.0,y:1.5,z:0.0)摄像头位置SCNVector3(x:0.0,y:1.5,z:0.0)
但是在我的设备上,我看到球落在地板上(用scn文件制作)并按预期运行.唯一的问题是我无法访问播放器的实际位置,因此无法移动我的相机.
我尝试过使用transform而不是position,这也没用.请帮忙!提前致谢!
| 归档时间: |
|
| 查看次数: |
1280 次 |
| 最近记录: |