I have a simple game that two lines moving from top to bottom of the screen. There is a fixed space between those two lines and a ball has to pass through in that space otherwise game is over.
I have no problem with the basics of the game, I can add two lines, a space which has different position every time but I also want to increase the moving speed of lines. I tried to use a timer and increase TimeInterval of SKAction.move but since lines which added later is faster, horizontal space between lines gets smaller which I don't want to happen.
This is the function that adds two lines and move them to bottom of the screen.
func addLines() {
let lineNodeFirst = SKSpriteNode(color: .red, size: CGSize(width: random(min: 100, max: 400), height: 10.0))
lineNodeFirst.position = CGPoint(x: -size.width / 2, y: 0 + size.height / 2 + 100)
lineNodeFirst.anchorPoint = CGPoint.zero
let actionMove = SKAction.move(to: CGPoint(x: lineNodeFirst.position.x, y: 0 - size.height / 2), duration: TimeInterval(2.3))
let actionMoveDone = SKAction.removeFromParent()
lineNodeFirst.run(SKAction.sequence([actionMove, actionMoveDone]))
let centerPoint = CGPoint(x: lineNodeFirst.size.width / 2 - (lineNodeFirst.size.width * lineNodeFirst.anchorPoint.x), y: lineNodeFirst.size.height / 2 - (lineNodeFirst.size.height * lineNodeFirst.anchorPoint.y))
lineNodeFirst.physicsBody = SKPhysicsBody(rectangleOf: lineNodeFirst.size, center: centerPoint)
lineNodeFirst.physicsBody?.isDynamic = true
lineNodeFirst.physicsBody?.categoryBitMask = 2
lineNodeFirst.physicsBody?.contactTestBitMask = 1
lineNodeFirst.physicsBody?.collisionBitMask = 0
self.addChild(lineNodeFirst)
let spaceBetweenNodes: CGFloat = 150
let lineNodeSecondWidth: CGFloat = size.width - lineNodeFirst.size.width - spaceBetweenNodes
let lineNodeSecond = SKSpriteNode(color: .red, size: CGSize(width: lineNodeSecondWidth, height: 10.0))
lineNodeSecond.anchorPoint = CGPoint.zero
let lineNodeSecondX = lineNodeFirst.position.x + lineNodeFirst.size.width + spaceBetweenNodes
lineNodeSecond.position = CGPoint(x: lineNodeSecondX, y: lineNodeFirst.position.y)
let actionMoveSecond = SKAction.move(to: CGPoint(x: lineNodeSecond.position.x, y: 0 - size.height / 2), duration: TimeInterval(2.3))
lineNodeSecond.run(SKAction.sequence([actionMoveSecond, actionMoveDone]))
let centerPointSecond = CGPoint(x: lineNodeSecond.size.width / 2 - (lineNodeSecond.size.width * lineNodeSecond.anchorPoint.x), y: lineNodeSecond.size.height / 2 - (lineNodeSecond.size.height * lineNodeSecond.anchorPoint.y))
lineNodeSecond.physicsBody = SKPhysicsBody(rectangleOf: lineNodeSecond.size, center: centerPointSecond)
lineNodeSecond.physicsBody?.isDynamic = true
lineNodeSecond.physicsBody?.categoryBitMask = 2
lineNodeSecond.physicsBody?.contactTestBitMask = 1
lineNodeSecond.physicsBody?.collisionBitMask = 0
self.addChild(lineNodeSecond)
}
I share a demo of my app which has the basics. Any suggestion for increasing move speed of lines?