精灵工具包节点实际上无法从父节点中删除

时间:2014-08-18 15:28:52

标签: ios swift sprite-kit

我用mutableArray制作了30个子弹来重复使用它们。

for var i = 0; i < 30; i++ {
    var bulletTmp = SharedAtlas.getInstance().getSpriteNode(SKSpriteType.bullet)

    bulletTmp.physicsBody = SKPhysicsBody(rectangleOfSize: bulletTmp.size)
    bulletTmp.physicsBody.dynamic = true
    bulletTmp.physicsBody.categoryBitMask = bulletCategory
    bulletTmp.physicsBody.contactTestBitMask = enemyCategory
    bulletTmp.physicsBody.collisionBitMask = enemyCategory

    moveBulletToTop = SKAction.moveToY(self.frame.height, duration: NSTimeInterval((self.frame.height - plane.position.y) / 400.0))

    bulletGroup.addObject(bulletTmp)
}

子弹是他们的父SKNode

bullets.runAction(SKAction.sequence([SKAction.waitForDuration(1.5), (SKAction.repeatActionForever(SKAction.sequence([SKAction.waitForDuration(0.05),SKAction.runBlock({
    var newBullet:MGSpriteNode!

    if self.bulletIndex < 29{
        self.bulletIndex++
    }else{
        self.bulletIndex = 0
    }
    newBullet = self.bulletGroup.objectAtIndex(self.bulletIndex) as MGSpriteNode

    newBullet.removeAllActions()
    newBullet.removeFromParent()
    print(self.childNodeWithName("bullets").children.count)//max value keeps 30

    newBullet.runAction(self.moveBulletToTop)

    newBullet.position = self.plane.position
    newBullet.position.y += self.plane.size.height * 0.5

    self.childNodeWithName("bullets").addChild(newBullet)

})])))]))

问题是:在子弹移动一段时间后,我已从父母移除。但屏幕上的节点数量不断增加。子弹的子女总是30岁。如果我移动所有的子弹,一切都会好的。但节点在哪里?他们真的被删除了吗?

0 个答案:

没有答案