Swift And Spritekit SceneDidLoad Being Called More Than One
I'm working with a simple game , I have MenuScene : the user can choose the type of the game and GamePlayScene .
First time user choose game type every thing is good , but the second time all methods called twice , and the third time methods called three time etc .
I try to use didMoveToView but still have the same problem.
should I delete the scene after finish the game ? if yes how?.
this is how I transition between scenes .
extension SKScene {
func presentSceneWith(NameOfScene scene : String){
if let scene = SKScene(fileNamed: scene){
scene.scaleMode = .aspectFill
self.view?.presentScene(scene)
}
}
}
I use it for present to GamePlayScene and back to MenuScene.
Answer
First : I'm using Firebase Database .
So the problem is : I was using If Statement inside the observe .
like :
private func searchForOpponents(){
let ref = Database.database().reference()
ref.child("activePlayers").child("waiting").observe( DataEventType.value) { (snapshot) in
// the problem when I put if statement like this
if snapshot == something {
presentToNextScene()
}
}
ref.observe called more than one in the second so basically I was present to next scene more than one time .
The solution : in my case I use ref.observeSingelEvent() and change the DataEventType to childChange .
Related Questions
- → Function Undefined in Axios promise
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Click to navigate on mobile devices
- → Playing Video - Server is not correctly configured - 12939
- → How to allow api access to android or ios app only(laravel)?
- → Axios array map callback
- → Access the Camera and CameraRoll on Android using React Native?
- → Update React [Native] View on Day Change
- → Shopify iOS SDK - issue converting BuyProductVariant to BuyProduct
- → BigCommerce and shopify API
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → React Native - Differences between Android and IOS
- → What is the difference between React Native and React?