我正在尝试为玩家精灵生成多个平台以便跳转。
这是我目前的代码:
var mainGroundAdded = false //starting ground for the player to run on
func addGround() {
let groundSize = CGSizeMake(self.frame.width/2, 50)
let ground = SKShapeNode(rectOfSize: groundSize)
ground.fillColor = SKColor.brownColor()
ground.name = "ground"
ground.physicsBody = SKPhysicsBody(rectangleOfSize: groundSize)
ground.physicsBody.affectedByGravity = false
ground.physicsBody.dynamic = false
ground.physicsBody.restitution = 0.0
ground.physicsBody.categoryBitMask = groundCategory
ground.physicsBody.collisionBitMask = rCategory
if (mainGroundAdded == false) {
ground.position = CGPointMake(0, 0)
mainGroundAdded = true
}
else {
ground.position = CGPointMake(self.frame.width+ground.frame.width, 0)
}
self.addChild(ground)
let move: SKAction = SKAction.moveToX(-ground.frame.width, duration: 4)
let remove = SKAction.removeFromParent()
ground.runAction(SKAction.sequence([move, remove]))
}
这就是我不断产生地面的方式
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
var timeSinceLast: CFTimeInterval = currentTime - self.lastUpdateTimeInterval
self.lastUpdateTimeInterval = currentTime
if (timeSinceLast > 1) {
timeSinceLast = 1.0 / 60.0
self.lastUpdateTimeInterval = currentTime
}
self.updateWithTimeSinceLastUpdate(timeSinceLast)
}
func updateWithTimeSinceLastUpdate(timeSinceLast: CFTimeInterval) {
self.lastSpawnTimeInterval = self.lastSpawnTimeInterval + timeSinceLast
if (self.lastSpawnTimeInterval > 1.5) {
self.lastSpawnTimeInterval = 0
self.addGround()
}
}
地面没有产生的其他地面那么大。我该如何解决这个问题?