0
\$\begingroup\$

This is the function i am trying to spawn obstacles in my game

func spawnObstacles() {
    let index = Int(arc4random_uniform(UInt32(obstacles.count)))

    let obstacle = obstacles[index].copy() as! SKSpriteNode

    obstacle.position = CGPoint(x: self.frame.width + obstacle.size.width, y: 50)

    let move = SKAction.moveTo(x: -(self.frame.size.width * 2), duration: 15)

    let remove = SKAction.removeFromParent()

    let sequence = SKAction.sequence([move,remove])

    obstacle.run(sequence)

    self.addChild(obstacle)
}

Here I am calling it

func initiazlize(){
    physicsWorld.contactDelegate = self
    createPlayer()
    createBg()
    createGrounds()
    createObstacles()

    Timer.scheduledTimer(timeInterval: 2, target: self, selector: Selector(("spawnObstacles")), userInfo: nil, repeats: true)

}

I am not sure why i am getting the error!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.