2016-03-07 27 views
5

yolunu takip et CGPath ile yarım daire yolunu nasıl oluşturacağımı bilmiyorum.CGPath ile yarım daire yolu oluşturma ve SKAction

let path = CGPathCreateMutable() 
    let Width: CGFloat = 38.0 
    let radius: CGFloat = (Width/2.0) + (Treshold/2.0) 
    CGPathAddArc(pathOne, nil, x, 0.0, radius, firstPoint.position.x, secondPoint.position.x, true) 
    let waitAction = SKAction.waitForDuration(1.0) 
    let moveAction = SKAction.followPath(pathOne, duration: 3.0) 
    capOne.runAction(SKAction.sequence([waitAction, moveAction])) 

cevap

7
import SpriteKit 

class GameScene: SKScene, SKPhysicsContactDelegate { 

    override init(size: CGSize) { 
     super.init(size: size) 
     let square = SKSpriteNode(color: SKColor.redColor(), size: CGSizeMake(20, 20)) 
     square.position = CGPointMake(self.size.width/2, self.size.height/2) 
     addChild(square) 

     let bezierPath = UIBezierPath(arcCenter: CGPointMake(0, 0), radius: 100, startAngle: CGFloat(M_PI_2), endAngle: CGFloat(-M_PI_2), clockwise: false) 

     let pathNode = SKShapeNode(path: bezierPath.CGPath) 
     pathNode.strokeColor = SKColor.blueColor() 
     pathNode.lineWidth = 3 
     pathNode.position = square.position 
     addChild(pathNode) 

     square.runAction(SKAction.followPath(bezierPath.CGPath, asOffset: true, orientToPath: true, duration: 2)) 
    } 

    required init?(coder aDecoder: NSCoder) { 
     fatalError("init(coder:) has not been implemented") 
    } 
} 
+0

sayesinde hamobi: i have kod yoktur. İşte bu yüzden arıyorum: –

+0

Bu spritleri yarım daire yolu ile değiştirmek istesem, startAngle ve endAngle'ı iki sprite konumundan nasıl hesaplayabilirim. Örneğini denedim, ama yarım dairen benim problemimi düzeltmiyor. İlk sprite'ı ikinciyle değiştirdiğimde iki sprite ait yarım daire yoluna ihtiyacım var, ve ikinci sprite'ı birinci olanlara taşıdığımda, bunların altında bir başka yarım daire. –

+1

belki başka bir soru yapabilir ve bazı kodları gönderebilir. :) – hamobi