2017-04-17 180 views
1

想製作一個類似於Paper.io的應用程序。我可以讓應用程序沿着它的路徑畫線。但無法創建封閉路徑。填充顏色的形狀像Paper.io

func action() 
    { 
    var action = SKAction() 
    switch direction { 
    case 1: 
     action = SKAction.moveBy(x:164,y:0,duration:0.6) 
    case -1: 
     action = SKAction.moveBy(x:-164,y:0,duration:0.6) 
    case 2: 
     action = SKAction.moveBy(x:0,y:164,duration:0.6) 
    case -2: 
     action = SKAction.moveBy(x:0,y:-164,duration:0.6) 


    default: 
     return 
    } 

    print("touch start ",posx,posy) 

    var repeatAction = SKAction.repeatForever(action) 

    ball.run(repeatAction, withKey: "Moving") 

    } 

回答

0

我相信你需要創造一個CGPath對象與運動一起。然後,您可以使用此路徑創建具有fillColor屬性的SKShapeNode

let path = CGMutablePath() 
// Construct the path e.g. using path.addLine(point:transform:) 

let shape = SKShapeNode(path: path) 
shape.fillColor = .blue