Post

Replies

Boosts

Views

Activity

How to add a 5 second delay to a function
I have a function that changes the Table type (background) at points in a game. The change happens ok but I am trying to add a 5 second delay before the switch from the current table type to the new table type but I cannot get the delay to work. The code for the replace table function is below. Any help would be great. func replaceTable() {         //add delay between table change         let secondsToDelay = 5.0         DispatchQueue.main.asyncAfter(deadline: .now() + secondsToDelay) {             // remove existing table before adding new one             if let table = self.currentTable {   table.removeFromParent()   self.currentTable = nil     }  }          let table = SKSpriteNode(imageNamed: tableType.imageName)   addChild(table)   table.position = CGPoint(x: size.width/2, y: size.height/2)   table.zPosition = -1   switch tableType {         case .bond:                 //...                 break             case .ovaloffice:                 //...                 break             case .austin:                 //...                 break             case .deadpool:                 //...                 break             case .moesbar:                 //...                 break             case .casino:                 //...                 break         }     }
1
1
7.5k
Dec ’20
Will an array of arrays work ?
Hi, Looking for some guidance on the best way to approach putting a feature in a card game app. Its a straight forward blackjack app that plays a set of sound files randomly. There are 7 arrays of sounds that contain 6 sound files in each. Each array contains files that are relevant to different game scenarios. The 6 sound files in each array play randomly when triggered. This all works fine. The next stage is to change the 7 arrays to another 7 arrays when the player score reaches 20 and then again at 40, 60 and so on. I tend to work slowly as I am a newby and was trying to avoid spending days or weeks heading down the wrong path for a solution. My experience is limited to tutorials I have watched. I am thinking an array of arrays might work but there might be another solution I havent come across yet.Any advice would be appreciated.
3
0
258
Oct ’20
How do I get this if statement to work?
I have a SKSpritnode table for a background in a game and I want the background to change as the players points reach a certain level eg every 20 points. I use a range operator as shown below. The code below builds and runs but background doesn't change. func setupTable(){ 				if(0...19).contains(playerScore) { 						let table = SKSpriteNode(imageNamed: "ovaloffice") 						addChild(table) 						table.position = CGPoint(x: size.width/2, y: size.height/2) 						table.zPosition = -1} 				else if(20...39).contains(playerScore)	{ 						let table = SKSpriteNode(imageNamed: "austin") 						addChild(table) 						table.position = CGPoint(x: size.width/2, y: size.height/2) 						table.zPosition = -1} 				else { 						let table = SKSpriteNode(imageNamed: "bond") 						addChild(table) 						table.position = CGPoint(x: size.width/2, y: size.height/2) 						table.zPosition = -1} 						func addPlayerScore() { 			playerScore += 1 			playerLabel.text = "Arn: \(playerScore)" 	}
9
0
480
Sep ’20