import SpriteKit

class MyScene: SKScene, SKPhysicsContactDelegate {
override func didMove(to view: SKView) {
...
physicsWorld.contactDelegate = self
}

func didBegin(_ contact: SKPhysicsContact) {
guard let name1 = contact.bodyA.node?.name else {return}
guard let name2 = contact.bodyB.node?.name else {return}
// logic deal with the contact
}
}
if let nextScene = SKScene(fileNamed: "GameScene") {
nextScene.scaleMode = scaleMode
let transition = SKTransition.flipVertical(withDuration: 0.5)
view?.presentScene(nextScene, transition: transition)
}
extension UIViewController {  
func alert(title: String, message: String) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
let alertAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(alertAction)
self.present(alertController, animated: true, completion: nil)
}

func alert(title: String) {
alert(title: title, message: "")
}
}
import StoreKit

func askUserToRate() {
var gamePlayed = UserDefaults.standard.integer(forKey: "gamePlayed")
gamePlayed += 1
UserDefaults.standard.set(gamePlayed, forKey: "gamePlayed")
if gamePlayed % 10 == 0 {
SKStoreReviewController.requestReview()
}
}

Cecil_Ma

System engineer. Indie iOS developer. Fan of table tennis and darts.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store