0

So I'm currently making a flappybird-like game using a tutorial and I have copied everything down the same but my pipes just keep spawning in the chosen spot and don't move horizontally at all. Any ideas on how to fix this? Here is my code so far:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if gameStarted == false {
        gameStarted = true

        Ghost.physicsBody?.affectedByGravity = true

        let spawn = SKAction.run { ()in
            self.createWalls()
        }

        let delay = SKAction.wait(forDuration: 2.0)
        let spawnDelay = SKAction.sequence([spawn, delay])
        let spawnDelayForever = SKAction.repeatForever(spawnDelay)
        self.run(spawnDelayForever)

        let distance = CGFloat(self.frame.width + wallPair.frame.width)
        let movePipes = SKAction.moveBy(x: -distance, y: 0, duration: TimeInterval(0.01 * distance))
        let removePipes = SKAction.removeFromParent()
        moveAndRemove = SKAction.sequence([removePipes, movePipes])


        let jumpUpAction = SKAction.moveBy(x: 0, y:180, duration: 0.2)
        Ghost.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
        Ghost.run(jumpUpAction)
rickster
  • 124,678
  • 26
  • 272
  • 326
Enuff
  • 1
  • You don't provide enough information to answer your question: Which tutorial do you read? What is your code snippet intended to do? – Lars Blumberg Jan 01 '17 at 11:07
  • I was watching a flappy bird tutorial by Jared Davidson, this snippet of code is meant to make the pipes spawn in and move from right to left as the ghost jumps thru them, only moving up and down. But the pipes on mine are all spawning in the same position and the nodes arent removing themself with the 'removeFromParent()' line. All i want is a quick and easy way yo spawn the pipes and move them right to left smoothly. Thank you – Enuff Jan 02 '17 at 21:53

2 Answers2

0

In your code snippet, you never call

self.run(moveAndRemove)

This is necessary to execute an action and it might be the reason why things get only spawned, i.e. triggered with

self.run(spawnDelayForever)

Can you check if that's the case?

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127
  • Same problem still. The pipes are spawning on top of each other and arent moving right to left. The pipes also arent being removed – Enuff Jan 02 '17 at 22:58
0

All fixed, i simply moved the block:

let distance = CGFloat(self.frame.width + wallPair.frame.width)
let movePipes = SKAction.moveBy(x: -distance, y: 0, duration: TimeInterval(0.01 * distance))
let removePipes = SKAction.removeFromParent()
moveAndRemove = SKAction.sequence([removePipes, movePipes])

and moved it into the first set of brackets. thanks heaps for the help though! :)

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127
Enuff
  • 1