У меня возникли проблемы с выяснением того, как мне следует создавать линию, которая исходит из точки A, и указывает на точку B (палец пользователя) и дальше. Такая линия может выглядетьЛиния вращения после пользователя touch
(A) происхождения (B) палец
------- B -----------
эта линия достигнет выключите экран и должны вращаться, когда пользователь перемещает свой палец. Также поможет код для создания строки и перемещения ее координаты B в режиме реального времени. Спасибо!
EDIT - Что я сделал до сих пор:
class GameScene: SKScene {
let testball = SKShapeNode(circleOfRadius: 50)
let testguy = SKShapeNode(circleOfRadius: 50)
let line = SKShapeNode()
let pathToDraw = CGPathCreateMutable()
override func didMoveToView(view: SKView) {
self.backgroundColor = UIColor(colorLiteralRed: 0.9, green: 0.9, blue: 1, alpha: 0.5)
testball.fillColor = UIColor.redColor()
self.addChild(testball)
self.testguy.position = CGPointMake(CGRectGetMinX(self.frame) + testguy.frame.width + 10, CGRectGetMinY(self.frame) + testguy.frame.height + 10)
self.testguy.fillColor = SKColor.redColor()
self.addChild(self.testguy)
CGPathMoveToPoint(pathToDraw, nil, testguy.position.x, testguy.position.y)
self.addChild(self.line)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
testball.position = (touches.first?.locationInNode(self))!
CGPathAddLineToPoint(pathToDraw, nil, (touches.first?.locationInNode(self).x)!, (touches.first?.locationInNode(self).y)!)
self.line.path = pathToDraw
self.line.strokeColor = UIColor.redColor()
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
testball.position = (touches.first?.locationInNode(self))!
//print(touches.first?.locationInView(self.view), appendNewline: true);
line.removeFromParent()
testball.position = (touches.first?.locationInNode(self))!
CGPathAddLineToPoint(pathToDraw, nil, (touches.first?.locationInNode(self).x)!, (touches.first?.locationInNode(self).y)!)
self.line.path = pathToDraw
self.line.strokeColor = UIColor.redColor()
self.addChild(line)
}
Вы сделали попытку? Большинство людей здесь любят сначала видеть ваш код. – Caleb
@Caleb Полностью забыл, спасибо! –