Всем привет. Пытаюсь установить слежение камеры за обьектом, но объект при загрузке двигается вверх.
class GameScene: SKScene, AnalogStickProtocol {
var oval: SKSpriteNode?
var World: SKNode!
var Camera: SKNode!
let moveAnalogStick: AnalogStick = AnalogStick()
let rotateAnalogStick: AnalogStick = AnalogStick()
override func didMoveToView(view: SKView) {
//camera
self.World = SKNode()
self.World.name = "World"
addChild(self.World)
self.Camera = SKNode()
self.Camera.name = "Camera"
self.World.addChild(self.Camera)
/* Setup your scene here */
let bgDiametr: CGFloat = 120
let thumbDiametr: CGFloat = 60
let joysticksRadius = bgDiametr / 2
self.backgroundColor = SKColor.yellowColor()
moveAnalogStick.bgNodeDiametr = bgDiametr
moveAnalogStick.thumbNodeDiametr = thumbDiametr
moveAnalogStick.position = CGPointMake(joysticksRadius + 15, joysticksRadius + 15)
moveAnalogStick.delegate = self
self.addChild(moveAnalogStick)
rotateAnalogStick.bgNodeDiametr = bgDiametr
rotateAnalogStick.thumbNodeDiametr = thumbDiametr
rotateAnalogStick.position = CGPointMake(CGRectGetMaxX(self.frame) - joysticksRadius - 15, joysticksRadius + 15)
rotateAnalogStick.delegate = self
self.addChild(rotateAnalogStick)
//camera
oval = SKSpriteNode(imageNamed: "oval2")
if let aN = oval {
aN.physicsBody = SKPhysicsBody(texture: aN.texture, size: aN.size)
aN.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
aN.physicsBody?.affectedByGravity = false;
//World.insertChild(aN, atIndex: 0)
World.addChild(aN)
}
self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
if let aN = oval {
Camera.position = CGPoint(x: aN.position.x, y: aN.position.y)
self.centerOnNode(Camera)
}
}
override func didFinishUpdate() {
}
func centerOnNode(node: SKNode) {
let cameraPositionInScene: CGPoint = node.scene!.convertPoint(node.position, fromNode: World)
node.parent!.runAction(SKAction.moveTo(CGPoint(x:node.parent!.position.x + cameraPositionInScene.x, y:node.parent!.position.y + cameraPositionInScene.y), duration: 1))
}
// MARK: AnalogStickProtocol
func moveAnalogStick(analogStick: AnalogStick, velocity: CGPoint, angularVelocity: Float) {
if let aN = oval {
if analogStick.isEqual(moveAnalogStick) {
aN.position = CGPointMake(aN.position.x + (velocity.x * 0.12), aN.position.y + (velocity.y * 0.12))
} else if analogStick.isEqual(rotateAnalogStick) {
aN.zRotation = CGFloat(angularVelocity)
}
}
}
}