屏幕上的多次触摸会导致fps下降

时间:2016-06-24 16:52:04

标签: ios swift skspritenode frame-rate

我正在尝试使用spritesnode快速编写游戏。 我使用了" touchesBegan"射击敌人和" touchesMoved"移动我的船。在短暂的几分钟后,fps从60下降到接近0,而内存保持低(30 MB),CPU几乎一直是100%。我有大约30个节点,15个Draws。 以下是"拍摄"

的代码
func fire() {

    laser = SKSpriteNode(imageNamed: "Laser")
    laser.name = "Laser"
    laser.size = CGSize(width: 20, height: 2)
    laser.position = ship.position

    if vitesse < 0 {
        let moveX = SKAction.moveBy (x: WidthScreen-ship.position.x, y: 0, duration: 0.5)
        let moveXDone = SKAction.removeFromParent()
        laser.run(SKAction.sequence([moveX, moveXDone]))
    } else {
        let moveX = SKAction.moveBy(x: -WidthScreen+ship.position.x, y: 0, duration: 0.5)
        let moveXDone = SKAction.removeFromParent()
        laser.run(SKAction.sequence([moveX, moveXDone]))
    }

    laser.physicsBody = SKPhysicsBody(rectangleOf: (laser.size))
    laser.physicsBody?.categoryBitMask = PhysicsCategory.Laser
    laser.physicsBody?.collisionBitMask = PhysicsCategory.Invaders | PhysicsCategory.SmartInvaders | PhysicsCategory.UfoToSmart
    laser.physicsBody?.isDynamic = false
    laser.zPosition = 3

    let soundAction = SKAction.playSoundFileNamed("Laser.wav", waitForCompletion: true);
    self.run(soundAction)

    self.addChild(laser)
}

和TouchesAction的代码

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch : UITouch = touches.first!
    var touchLocation = touch.location(in: self)
    if touchLocation.y > 88*HeightScreen/100 {
        touchLocation.y = 88*HeightScreen/100
    }
    if touchLocation.y < HeightScreen/15 {
        touchLocation.y = HeightScreen/15
    }
    elevation = touchLocation.y
}


override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
   /* Called when a touch begins */
    if lifeArray.count>0{
        fire()
    }
}

有人会知道问题的来源吗? 谢谢你的帮助

此致

Here image of CPU instruments

0 个答案:

没有答案