Restarting Sprite - Kit Game Swift

我是研究僧i 提交于 2019-12-06 09:01:09

If you're trying to restart a scene, you can just present the same scene and it resets back to its defaults:

let scene = GameScene(size: self.size) // Whichever scene you want to restart (and are in)
let animation = SKTransition.crossFade(withDuration: 0.5) // ...Add transition if you like
self.view?.presentScene(scene, transition: animation)

Put this code in whichever scene you are in and wish to restart. It should be called when you want to restart the scene.

You might just want to not show an animation (or do a cross fade) if you're trying to make a seamless transition.

Alternatively, you may want to create a game over scene/menu. This could just be another SKNode that becomes visible once the game resets or even another scene.

First of All, you should check both cases, If player is Contact A or if Player is Contact B. Secondly, you should assign the object you want to remove, lets says the obstacle, to a variable, for example lets says that Object B es the Obstacle, Then: contact.bodyB.node.removeFromParent() and you will successfully remove the object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!