在删除节点之前动画SKAction一次

时间:2016-07-11 16:12:09

标签: ios swift animation

我正在制作游戏,并且我在didBeginContact函数中实现了一些内容。

基本上,我的家伙抛出projectile,当projectile连接时,我需要projectile消失,enemy点击以执行animation if let node = contact.bodyB.node as? SKSpriteNode { if node.parent != nil { let moveUp = SKAction.moveBy(CGVector(dx: 0, dy: -100), duration: 0.5) let fadeOut = RocketExp let runBlock = SKAction.runBlock{ () -> Void in node.removeFromParent() } let remove = SKAction.removeFromParent() let moveAndFade = SKAction.group([moveUp, fadeOut]) let sequence = SKAction.sequence([fadeOut, runBlock, remove]) node.runAction(sequence) node.removeFromParent() } } 然后敌人就消失了。

我可以得到它,以便敌人动画播放一次然后消失,但我的射弹没有,或者我可以让敌人和射弹消失,但没有动画显示。

到目前为止,这是我的代码:

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Detailed Error Information 
Module
IIS Web Core 
Notification
BeginRequest 
Handler
Not yet determined 
Error Code
0x80070032 
Config Error
The configuration section 'log4net' cannot be read because it is missing a section declaration  
Config File
\\?\C:\Synxis\trunk\ProjectX\Synxis\Application\Interfaces\Interface\web.config 
Requested URL
http://localhost:80/Interface/Oxi.aspx 
Physical Path
C:\Synxis\trunk\ProjectX\Synxis\Application\Interfaces\Interface\Oxi.aspx 
Logon Method
Not yet determined 
Logon User
Not yet determined 
Config Source   420: 
  421:   <log4net>
  422: 

我非常确定node.removeParent()只是删除了被命中的两个节点。

1 个答案:

答案 0 :(得分:1)

尝试这样做

let enemyCategory: UInt32 = 0x1 << 0
let missileCategory:  UInt32 = 0x1 << 1

enemy.physicsBody?.categoryBitMask = enemyCategory
enemy.physicsBody?.contactTestBitMask = missileCategory 

missile.physicsBody?.categoryBitMask = missileCategory
missile.physicsBody?.contactTestBitMask = enemyCategory

func didBeginContact(contact: SKPhysicsContact) {
    if body1.categoryBitMask == enemyCategory && body2.categoryBitMask == missileCategory{
       // your code here
       body2.node?.removeAllActions()
       body2.node?.removeFromParent()
   }
}