从父母那里取出后,如何重生敌人的节点?
我试图在被杀死后将另一个敌人添加到屏幕上,但这似乎对我不起作用,因为我没有得到新的敌人。如果您有任何与我的问题相似的链接,我也会很感激!谢谢(让我知道您是否需要查看更多代码,我只会发布函数,因为我认为在这种情况下,这是唯一要显示的相关内容)
func projectileDidCollideWithMonster(projectile: SKSpriteNode, monster: SKSpriteNode) {
print("Hit")
run(SKAction.playSoundFileNamed("enemy-contact.mp3", waitForCompletion: false))
projectile.removeFromParent()
monster.removeFromParent()
//here is my code that should add the monster back after 2 sec
monster.run(SKAction.wait(forDuration: 2)) {
self.addChild(monster)
}
}
I am trying to add another enemy to the screen after it has been killed, but this doesn't seem to be working for me because I am not getting a new enemy. If you have any links that are similar to my problem I would appreciate that too! thanks ( let me know if you need to see more code I only have the function posted because I think thats the only relevant thing to show in this case)
func projectileDidCollideWithMonster(projectile: SKSpriteNode, monster: SKSpriteNode) {
print("Hit")
run(SKAction.playSoundFileNamed("enemy-contact.mp3", waitForCompletion: false))
projectile.removeFromParent()
monster.removeFromParent()
//here is my code that should add the monster back after 2 sec
monster.run(SKAction.wait(forDuration: 2)) {
self.addChild(monster)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Monster
不再是场景的一部分,因此它没有运行任何内容。您只需要翻转订单并在现场运行动作即可。monster
is no longer part of the scene, so it's not running anything. You just need to flip the order around and run the action on the scene.