从父母那里取出后,如何重生敌人的节点?

发布于 2025-01-21 16:34:56 字数 566 浏览 4 评论 0原文

我试图在被杀死后将另一个敌人添加到屏幕上,但这似乎对我不起作用,因为我没有得到新的敌人。如果您有任何与我的问题相似的链接,我也会很感激!谢谢(让我知道您是否需要查看更多代码,我只会发布函数,因为我认为在这种情况下,这是唯一要显示的相关内容)

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧梦荧光笔 2025-01-28 16:34:56

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文