2017-05-06 50 views
0

我使用了swift,并且我获得了该函数。调用函数后更改位置

FUNC spawnTwo() - > SKSpriteNode {

let two = SKSpriteNode(imageNamed: "landPic1") 
    two.anchorPoint = CGPoint(x: 0.5, y: 0.5) 
    two.name = "Obs" 
    two.zPosition = 5; 
    two.anchorPoint = CGPoint(x: 0.5 , y: 0.5); 
    two.position.x = 0 
    two.position.y = 0 

    self.scene?.addChild(two) 


    return two 

}

现在我想,我每次调用该函数时,1280加入position.x。我怎么做?

回答

1

只要保持函数的变量外:

var n = 0 
func spawnTwo() -> SKSpriteNode { 

    //... 
} 

在功能,您可以通过n乘以1280增加n

let two = SKSpriteNode(imageNamed: "landPic1") 
two.anchorPoint = CGPoint(x: 0.5, y: 0.5) 
two.name = "\(n)bs" // you might want to change the name each time too 
two.zPosition = 5; 
two.anchorPoint = CGPoint(x: 0.5 , y: 0.5); 
two.position.x = 1280 * n 
two.position.y = 0 

self.scene?.addChild(two) 
n += 1 

return two 
+0

你的天才哈哈哈非常感谢你:) – Chief