【发布时间】:2017-04-25 23:13:39
【问题描述】:
看来我在这里问了很多问题。我现在需要知道如何让敌人在物品被摧毁后掉落它。我有它,所以当玩家与敌人碰撞时,它会摧毁敌人,但我需要它,所以当敌人被摧毁时,它会在它的位置产生一个物品。
这是消灭敌人的代码:
func handleAttackButtonHover(isHovering : Bool) {
if isHovering {
attackButton.texture = attackButtonPressedTexture
invincible = true
print("invincible = true")
playerNode?.removeAction(forKey:"animate")
playerNode?.run(attackAnimation,completion:{
self.playerNode?.run(self.animation,withKey: "animate")})
} else {
attackButton.texture = attackButtonTexture
invincible = false
print("invincible = false")
playerNode?.removeAction(forKey:"attackAnimation")
playerNode?.run(animation,completion:{
self.playerNode?.run(self.animation,withKey: "animate")})
}
}
还有:
//physicsbody for player and enemies and coins
func didBegin(_ contact: SKPhysicsContact) {
// var bodyA = SKPhysicsBody()
// var bodyB = SKPhysicsBody()
//print("collision detected")
if contact.bodyA.node?.name == "player" || contact.bodyB.node?.name == "player" {
//print("collision detected")
if contact.bodyA.node?.name == "enemy" {
if invincible == true {
contact.bodyA.node?.removeFromParent()
} else {
contact.bodyB.node?.removeFromParent()
}
} else if contact.bodyB.node?.name == "enemy" {
if invincible == true {
contact.bodyB.node?.removeFromParent()
} else {
contact.bodyA.node?.removeFromParent()
}
}
}
}
【问题讨论】:
-
那么,具体问题是什么?为什么要转储代码?
-
我展示了我是如何设置摧毁敌人的。我需要的是我不知道制作它需要什么代码,所以当敌人被摧毁时,我会在那里产生一个物品
-
您是否尝试过任何方法来实现它,或者您只是从获得的答案中复制粘贴代码?
标签: swift sprite-kit