Posts

Showing posts with the label sprite-kit

Reference to a TableView Delegate Object within a Scene in Swift 4

Reference to a TableView Delegate Object within a Scene in Swift 4 I have a tableview in a SpriteKit scene. Using a tableview delegate method, I like to pass to another scene/ViewController, which cell was selected. There is only a single storyboard as this is entirely a SpriteKit game. //TableView inside Scene & Delegate Protocol: protocol gameSelectedDelegate { func theGameSelected(gameInt: Int) } class GamesTableView: UITableView, UITableViewDelegate,UITableViewDataSource { //Test Data var items: [String] = ["Player1", "Player2"] let defaults = UserDefaults.standard var gamesList = [Game]() var passedGame: Int? //instance of delegate var selectionDelegate: gameSelectedDelegate!` //GameScene to receive tableview data and delegate for my tableview class GamePlay: SKScene, gameSelectedDelegate { var backButton = SKLabelNode(fontNamed: "ArialRoundedMTBold") var score = SKLabelNode(fontNamed: "ArialRoundedMTBold") var passedGame = 0 //Not gett...

how to generate random numbers from 1 to 4 and 8 in swift

how to generate random numbers from 1 to 4 and 8 in swift I'm making an iOS SpriteKit game right now for first time I'm developing any app and it's tough challenge for me because it's really a big project for first time. My game is a Dice game and I defined move as 4 number. So when ever I touch the screen Player moves 4 blocks, But now I want to add Dice to the Game and I need Numbers from 1 to 4 and 8. So it will be 1,2,3,4 and 8 Numbers in the Dice. I know in Swift we can get Random Numbers with "arc4random" but how do I get numbers 1 to 4 and also 8 can I do it with arc4random and if possible I need 4 and 8 numbers to come 20% more often. Any Help will be really Helpful. Thanks. This might be helpful for you - stackoverflow.com/questions/32552336/… – Md Rashed Pervez Jul 1 at 10:45 S...